Brandon_R Posted July 23, 2009 Share Posted July 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
ldougherty Posted July 23, 2009 Share Posted July 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
Brandon_R Posted July 23, 2009 Author Share Posted July 23, 2009 Thanks Ill Try That Out Quote Link to comment Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 You also need to attach the onselect to the <select> tag, not the <option> tags. Quote Link to comment Share on other sites More sharing options...
vineld Posted July 24, 2009 Share Posted July 24, 2009 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. 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.