Solved

Error when I use getElementsById.display

Posted on 2007-11-21
9
919 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Interview question Javascript, database 12 57
How can i get the length? 7 31
Converting dates in JavaScript 2 32
Hide cell in a table 2 9
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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 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