Solved

If the country is US select a state

Posted on 2007-11-20
3
772 Views
Last Modified: 2013-11-19
Hello Everyone, Is there a way to get it so that either the state is disabled until the country selected is United States,

OR

have the state row appear ONLY if the country selected is United States?

Can you help me write either of these type of code?

I'm not sure how to make a state disabled, or would it be easier to get the whole state row to dissappear unless the country selected is United Satets

      <TR>
            <TD class="number">&nbsp;</TD>
        <TD class="question">State:<font color="#FF0000">*</font></TD>
                  <TD class="response"> <select name="AuthorizedRepState" id="AuthorizedRepState" style="font-family: Verdana; font-size: 8pt">
          <% showStates sAuthorizedRepState %>
        </select></TD>
      </TR>
      <TR>
            <TD class="number">&nbsp;</TD><TD class="question">Country:<font color="#FF0000">*</font></TD>      <TD class="response">
            <select name="AuthorizedRepCountry" id="AuthorizedRepCountry" style="font-family: Verdana; font-size: 8pt">
            <% showCountries sAuthorizedRepCountry %>
            </select>
            </TD>
      </TR>
0
Comment
Question by:Gemini532
3 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20324383
Gemini532,

The state row in your code, like that in other sites, has the Country field after the state one.  It usually is not worthwhile to disable a previous field.  However if you want use ...

            <select name="AuthorizedRepCountry" id="AuthorizedRepCountry" style="font-family: Verdana; font-size: 8pt" onchange="document.forms[0].AuthorizedRepState.disabled = (this.value != '' || this.value != 'United States')? true : false;">

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 9

Assisted Solution

by:blue_hunter
blue_hunter earned 100 total points
ID: 20325315


<select name="AuthorizedRepCountry" id="AuthorizedRepCountry" style="font-family: Verdana; font-size: 8pt" onchange="checkState(this)">
            <% showCountries sAuthorizedRepCountry %>
            </select>
 
 
<script language="javascript">
function checkState(hdl){
if(document.getElementById("AuthorizedRepState")){
if(hdl.value == "United States")
{
   document.getElementById("AuthorizedRepState").disabled = false;
} else {
   document.getElementById("AuthorizedRepState").disabled = true;
}
}
}
</script>

Open in new window

0
 
LVL 5

Accepted Solution

by:
palanee83 earned 400 total points
ID: 20327006
you can do this by javascript...
just place the state information with the div
when it load the first time it should be like this
<div id='allstate' style="display:none">
//populate state here
</div>

by using onChange() javascript event you can show the "allstate" div when the value equal to US

if(slectedvalue==US)
{
document.getElementId('allstate').disply.style="block";
}
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question