Click here to Skip to main content
15,885,898 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

Please need help guys,

I have a button on the page , each time we click that adds dropdownlist items on to the page.

So if i click the button 3 times so i will have 3 dropdownlist items on the page.

Now the problem is i wants to validate them,

I am using this..
JavaScript
var extrapetid = document.getElementsByTagName('select');
       for (i = 0; i < extrapetid.length; i++) {

           var value = $("extrapetid[i] option:selected").val();
           if (extrapetid[i].val() == "") {
               valid = false;
            }
         }


I wants to check if the seleted value is "" make it valid=false.
I am using it to iterate each select item on the page and get the selected value of it but

But no luck in that i always getting error or not getting the value.

Please help me
Posted
Updated 24-Apr-17 3:01am
v2

1 solution

jQuery can't parse this to know that extrapetid[i] needs to be evaluated. Instead, add an index to the name for each control, like control1, control2, then use extrapetid[i] to access the object, and get it's unique id and pass that to jquery as normal. Having lots of controls with the same id is not a good idea. How do you tell them apart ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900