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. Link to comment https://forums.phpfreaks.com/topic/86220-solved-help-w-drop-down-boxform/ 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 Link to comment https://forums.phpfreaks.com/topic/86220-solved-help-w-drop-down-boxform/#findComment-440486 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 { } } Link to comment https://forums.phpfreaks.com/topic/86220-solved-help-w-drop-down-boxform/#findComment-441091 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> Link to comment https://forums.phpfreaks.com/topic/86220-solved-help-w-drop-down-boxform/#findComment-441409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.