Solved

Error when I use getElementsById.display

Posted on 2007-11-21
9
916 Views
Last Modified: 2013-11-19
Hello Everyone,
       
I want the US states drop down menu to appear only when the country that is selected is: United States

  Originally I got the following JavaScript pop up error:

                    document.getElementsById(...).display' is null or not an object

And it was coming from the following line:

                     document.getElementsById("allstate").disply.style="block";


But after I changed the code to:
                               document.getElementsById("allstate").disply="block";
the error went away...

However, I still cannot see the state row, so I can select a state now that the country is the United States, so I still need your help with this question!!

Can you help me?  I bet I'm missing something... synthax error... maybe...



Here is my code:

<form action="115-002.asp" id="OPICForm" name="OPICForm" method="post" onSubmit = "return validateSubmit();" >

<table>
      <TR id = "allstate" style="display:none;">
            <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" onChange="ShowAllStates();">
            <% showCountries sAuthorizedRepCountry %>
            </select>
            </TD>
      </TR>
</table>

<script>
   //Angie H. 11/21/07 -- By using onChange() javascript event you can show the "allstate" div when the value equal to US
      function ShowAllStates(){
            if(document.OPICForm.AuthorizedRepCountry.value =="United States")
            {
            document.getElementsById("allstate").disply.style="block";
            }
      }      
</script>

What do you think, what am I doing wrong?  


0
Comment
Question by:Gemini532
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20328327
There is no getElementsById function.  You want:
document.getElementById

Open in new window

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20328337
And it should be:

document.getElementById(id).style.display = 'block';

Open in new window

0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20328396
It should be like

document.getElementsById("allstate").style.disply="block";
0
 

Author Comment

by:Gemini532
ID: 20331015
I changed the function to:

   //Angie H. 11/21/07 -- By using onChange() javascript event you can show the "allstate" div when the value equal to US
      function ShowAllStates(){
            if(document.OPICForm.AuthorizedRepCountry.value =="United States")
            {
            document.getElementById("allstate").style.disply="block";
            //document.getElementsById("allstate").style.disply="block";
            }
      }
but I still do not see the STATES DISPLAYING ON THE SCREEN!!!

Something else must be wrong... can you help me find out what?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 21

Expert Comment

by:nizsmo
ID: 20331359
Try:
document.getElementById("allstate").style.disply="inline";
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20331366
dam i just realized u (also I) spelt display wrong!

document.getElementById("allstate").style.display="block";

or

document.getElementById("allstate").style.display="inline";

one of them should work, if not both.
0
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 500 total points
ID: 20333344
spelling mistake for display.
document.getElementById("allstate").style.display="block";
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20354238
Not that I'm one to complain, but two other people answered the question correctly before the accepted answer, so why not, at the very least, a point split?
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20355596
hmm interesting point allocation. may I ask why not a point split @ least to Morcalavin, who was actually the first to pick up the spelling mistake way before the other posts?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 how to look for a specific file type in a local or remote server directory using PHP.

757 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

22 Experts available now in Live!

Get 1:1 Help Now