cpd Posted June 2, 2009 Share Posted June 2, 2009 Hello, im trying to set an input tag so that it has "EUF" permanantly in it however the user can still type text AFTER the "EUF" text. Could someone please push me on my way an tell me how to do this using JS? thankyou Quote Link to comment Share on other sites More sharing options...
Adam Posted June 2, 2009 Share Posted June 2, 2009 HTML has a "maxlength" attribute you should look into. If you don't want the user to be able to change it at all, an input is perhaps not the best way to go. You could setup a bit of JavaScript on the element though to make it default back to a value when the user loosees focus on the input (onblur): <input (...) onblur="this.value='EUF';" /> Quote Link to comment Share on other sites More sharing options...
cpd Posted June 2, 2009 Author Share Posted June 2, 2009 Yeah ive done that already and that works absolutely fine but they can still delete that text and type something else. i just dont want them to delete it what so ever... Quote Link to comment Share on other sites More sharing options...
Adam Posted June 2, 2009 Share Posted June 2, 2009 If you don't want the user to change the value from "EUF" at all, perhaps you shouldn't be using an input..? If the input's there for some design reasoning, perhaps use the disabled attribute, or, you could use a hidden input and just write the text "EUF" normally? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 2, 2009 Share Posted June 2, 2009 I agree with the last. Just put EUF as text just before the input field, so the user knows to enter the EUF code without the EUF text. Then add EUF to the input on the server-side before you use it. Something like: EUF<input type="text" name="EUFCode" /> Quote Link to comment Share on other sites More sharing options...
Axeia Posted June 2, 2009 Share Posted June 2, 2009 If you want it to look as if it's in the input field you could a big left padding on the input and position absolute for positioning the text over it. HTML forms do not (yet?) allow masked textboxes like those found in programming languages. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.