Jump to content

[SOLVED] Help W/ drop down box/form


gigantorTRON

Recommended Posts

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

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
{
}

}

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.