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

}

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.