justAnoob Posted April 28, 2009 Share Posted April 28, 2009 sorry to post this here,, but no one is ever on the other boards... I'm looking to put some validation on my listmenu on my page.. the validation for my textfields work great ex. <input name="item_name" type="text" id="item_name" size="50" /><span id="item_name_error" class="error"></span> if (!form1.item_name.value) { document.getElementById('item_name_error').innerHTML = 'Please enter a name.'; valid = false; } else { document.getElementById('item_name_error').innerHTML = ''; } thats works perfectly now how would i go about adding the span id into a listmenu?? <select name="listmenu" size="1" id="listmenu"> <option selected="selected">Please select category</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> basically i would like it to say something like if (form1.listmenu.value = "Please select category") { document.getElementById(listmenu_error').innerHTML = 'You did not choose a category.'; valid = false; } I have tried a couple variations,, but I'm still new to all this.. Anyone have any input? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 28, 2009 Share Posted April 28, 2009 <select name="listmenu" size="1" id="listmenu"> <option selected="selected" value="0">Please select category</option> <option value="1">1</option> Assign values to the option tags, as the innerHTML is just a text representation. Check the values by using the selectedIndex's value. if (form1.options[options.selectedIndex].value == "1") { //do something } The if statement should be accurate, but if not google "selectedIndex" to find the right way. You might have to change the referencing in relation to your form/select names. Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted April 28, 2009 Share Posted April 28, 2009 justAnoob, just dropping by to ask that for future reference, please use a more descriptive thread title (like perhaps 'listmenu validation help' or something along those lines in this case), and not something like 'anyone?'. Being descriptive helps give other members a better idea of the issue at hand at a glance (and as a result, you might get their participation instead of them simply passing you by deliberately). 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.