how to add values into dropdown in java script
I saw a sample code in this website to dynamically populate second dropdown men based on a selection of first dropdown. I have account number dropdown and based on the selection, I need to populate second dropdown with corre开发者_开发知识库sponding email-id. code is here :Populating Child Dropdown (second option using java script).
But can someone let me know how to populate the values inthe second dropdown ?
<script>
var dd2options = ${dd2optionsAsJSObject};
var dd3options = ${dd3optionsAsJSObject};
function dd1change(dd1) {
// Fill dd2 options based on selected dd1 value.
var selected = dd1.options[dd1.selectedIndex].value; ... }
</script>
My code is as below- how to change the code to do this ?
<td>
1. Member Account Number
<span class="bodyCopy">
<font color="#ff0000"> * </font>
</span>:
<html:select
name="DataForm"
property="Member.accountNumber"
styleClass="formContent"
style="width:80px">
<html:options collection="<%= WorkConstants.RENewDropdowns.PACCT %>"
property="value"
labelProperty="label"
styleClass="formContent"/>
</html:select>
</td>
My second dropdown is as below:
<td>
3. Member <br>E-mail Address:<br />
<span class="bodyCopy"></span>
<html:select
name="DataForm"
property="Member.emailAddress.emailAddress"
style = "width:150px"
styleClass="formContent">
<html:options collection="<%= WorkConstants.RENewDropdowns.PEMAIL %>"
property="value"
labelProperty="label"
styleClass="formContent"/>
</html:select>
</td>
Appreciate your help on this as I'm new to java script.
Problem can be solved in following ways
Using onchange event of select element, on first box submit form and populate data in second select box.
Use ajax to fetch data in the same way instead of submitting form
Fetch all the main and related data, store them in arrays. Call them according to key. You can use JSON to solve
精彩评论