Solved

If the country is US select a state

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery Syntax... 4 50
Passing client data from form to server 5 13
Problem evaluating javascript equality expression 8 17
Put POST values into cookies. 14 28
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa‚Ķ
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.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

679 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