Solved

If the country is US select a state

Posted on 2007-11-20
3
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

751 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