Solved

If the country is US select a state

Posted on 2007-11-20
3
770 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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:
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now