kts Posted July 1, 2008 Share Posted July 1, 2008 I have a select(drop down) and i am trying to validate it to make sure its not on the default "Select One" The name is id[24] but when doing this in the javascript it is not recognizing if(document.cart_quantity.id[24].selectedIndex == 0){ alert("Bread"); return false; } I have also tried if(document.cart_quantity.id[24].value == 0){ alert("Bread"); return false; } Can anyone help? Thanks. Link to comment https://forums.phpfreaks.com/topic/112830-php-array-javascript-validation/ Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 if id[24] is the id of your select object, then id[24].value will contain the value that is in the value property of the corresponding option object. So you can just do this: <select id="id[24]"> <option value="default">default</option> </select> <script> if (document.cart_quantity.id[24].value == "default") alert("Bread"); </script> I am assuming cart_quantity is the id of your form. Link to comment https://forums.phpfreaks.com/topic/112830-php-array-javascript-validation/#findComment-579535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.