简体   繁体   中英

How do I have my drop down selections submit in the HTML form?

I have these conditional drop lists behaving on screen as expected, but I cannot get the selected values from the drop downs to output in the HTML form (I can if I don't include the javascript). Only the text inputs are outputing as per the xml result below (Company & Add1). I want the xml to contain the Location from the first drop down, and the selected city from the conditional 2nd drop down.

 <body> <form action="http://TESTPLANETPRESS:8080/ObtainQuote" method="GET" > <fieldset> <legend>Location</legend> <select id="country" class="source" onchange="updateSelectTarget()"> <option value="England">England</option> <option value="France">France</option> <option value="Germany">Germany</option> </select> <select id="England"> <option value="Birmingham">Birmingham</option> <option value="Liverpool">Liverpool</option> <option value="London">London</option> </select> <select id="France" class="hidden"> <option value="Lyon">Lyon</option> <option value="Marseille">Marseille</option> <option value="Paris">Paris</option> </select> <select id="Germany" class="hidden"> <option value="Berlin">Berlin</option> <option value="Hamburg">Hamburg</option> <option value="Munich">Munich</option> </select> <label for="Company">Company:</label><input type="text" name="Company" value="Google"> <label for="Add1">Add1:</label><input type="text" name="Add1" value="1 Nowhere Street"> </fieldset> <input type="submit" value="Submit"> </form> <script> function updateSelectTarget () { var id = this.options[this.selectedIndex].value; var targets = this.parentNode.getElementsByTagName("select"); var len = targets.length; for (var i = len - 1; i > 0; --i) { if (targets[i].id == id) { targets[i].style.display = "block"; } else { targets[i].style.display = "none"; } } } function initChangeHandler () { var el = document.getElementById("country"); el.onchange = updateSelectTarget; el.onchange(); } window.onload = initChangeHandler; </script> </body> 

Current XML result, (Does not include the results from the two drop downs).

<?xml version="1.0"?>

-<request type="GET">

<paths count="0"/>


-<values count="2">

<Company>Google</Company>

<Add1>1 Nowhere Street</Add1>

</values>

Do you want the value attribute or the text? Based on Get selected value in dropdown list using JavaScript? (similar to the first part), .value should work for the value attribute and .text for the text that is selected.

Also, please make two different questions instead of one question with 2 questions nested inside.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM