Is it possibe to get the value of a dropdown list via javascript? When I look at the page source I don't see a control rendered. I only see Javascript.
Is it possibe to get the value of a dropdown list via javascript? When I look at the page source I don't see a control rendered. I only see Javascript.
Best answer by s95f
Hello Disa!
It is possible do grab the value from a drop down. Depending on you designed your form you may need to tweek the below code:
var x = document.getElementsByClassName("input-control styling-font");console.log(x[0].children[0].title);
The class of objects you wanna be targeting is of both of these classes -> input-control and styling font. If you have more than one drop down list you may want to consider also targeting the cell. You should be able to rip apart the table to find the proper references if you are checking out the HTML. They should be ordered just like it is in designer if you are using tables for orginization. You could also solve the problem another way once you notice the pattern of how it grabs the list of elements. Instead of just using x[0] you can loop over the array of elements and there should be a noticible pattern to how you orginized your dropdown lists and how they appear in the list.
The above code assumes two things, there is currently a value in the control and there is only one control. When you target the element you essentially wanna grab it's child and there is two ways to extract the data. You can do what I did and grab the title or you can grab the inner text of the HTML tag which should be holding the same value.
Let me know if there is any way I can improve this answer.
- Steven
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.