Jump to content

Setting a minimum length or something similar


cpd

Recommended Posts

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

Link to comment
Share on other sites

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';" />

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.