Solved

Error when I use getElementsById.display

Posted on 2007-11-21
9
920 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 dynamically set the form action using jQuery.

856 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