gigantorTRON Posted January 15, 2008 Share Posted January 15, 2008 Hey guys. Quick question here... I have two sections of a form that contain dropdown boxes. If a user selects dropdownbox index #1, then I need the 2nd drop down box to populate with certain data. If they select #2, then I need the field to be a text box, not drop down. What's the easiest way to do this? Thanks. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 16, 2008 Share Posted January 16, 2008 start here: http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=Javascript+Chained+Select+Menu&spell=1 you should be able to find several examples/tutorials on how to do this Quote Link to comment Share on other sites More sharing options...
gigantorTRON Posted January 16, 2008 Author Share Posted January 16, 2008 Well... I don't really need it to be that complex. I already have a PHP function to print out the second drop down box. Here's the situation: New registrant must select their country upon registration (Select box 1). If they select the United States or Canada, then Select box 2 populates the US and CA states. Else, a text box is displayed. So I need to dynamically control the type of form element based on what country is selected. Is this possible?? Here's what I have so far (js n00b) function printStates() { var selectedCountry = document.custForm.post_Customer_Country.selectedIndex; if (selectedCountry=='US' || selectedCountry=='CA') { } else { } } Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 16, 2008 Share Posted January 16, 2008 ok - well here is my simple rendition of what your wanting to do. <script language="javascript"> function checklocal(yourarea) { var selectedCountry = document.getElementById(yourarea).value; if ((selectedCountry == "US") || (selectedCountry == "CA")) { document.getElementById("step2").innerHTML="<select name=\"statesorterr\"><option>Select Your Location</option><option value=\"StateOrTerrHere\">State or Territory Options</option></select>"; } else if (selectedCountry == "Other") { document.getElementById("step2").innerHTML="<input type=\"text\" name=\"other\">"; } else { document.getElementById("step2").innerHTML=""; } } </script> <select id="picker" onchange="checklocal(this.id)"> <option selected value="">Select Country</option> <option value="US">United States</option> <option value="CA">Canada</option> <option value="Other">Other</option> </select> <span id="step2"></span> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.