Solved

If the country is US select a state

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

622 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