Jump to content

PHP Array / Javascript Validation


kts

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

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