Jump to content

Custom Maxlength Based On What Is Selected


Brandon_R

Recommended Posts

Hello wonderful members of this forum i need some help with this form. What i'm trying to do is give an input field a custom maxlength based on what a user selects from the selection drop down. Here  is what i have so far:

 

<select disabled="disabled" name="key_select">

<option value="">Please Choose</option>

<option value="Describe Yourself">Describe Yourself</option>

</select>

 

<input type="text" class="bginput" name="description"  size="50" maxlength="0" />

 

Notice the maxlength is 0 but when the user clicks on describe Yourself i want it to update the max length to 50. I tried this code but still nothing

 

<select disabled="disabled" name="key_select">

<option value="">Please Choose</option>

<option value="Describe Yourself" onclick="javascript:document.information_form.description.maxlength=50>Describe Yourself</option>

</select>

 

<input type="text" class="bginput" name="description"  size="0" maxlength="0" />

 

Please tell me how to achieve this or if it is even possible :)

Thank You

Brandon_R

 

Link to comment
Share on other sites

What you need to do is change the value of the length field using the on select javascript function

 

I don't have the code off hand but the idea is that when a user selects something from the drop down (ie on select) the document.description.size should be adjusted.

 

If you do a quick search on Google for on select you'll find a wealth of walk throughs.

Link to comment
Share on other sites

Like said before, no events should be added to the option tags but the select. You could however use onchange which will work just fine and you should use document.getElementById("description") instead and add an id attribute to the description field.

 

Try looking at jQuery as well if you haven't already, it will make all javascripting much quicker for you.

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.