Forum Moderators: open

Message Too Old, No Replies

why would java think a statement is a function call?

another "What am I doing wrong here" moment

         

Baruch Menachem

2:11 pm on May 20, 2008 (gmt 0)

10+ Year Member



I am copying text out of a book, and this works fine for the author, but I am missing something obvious, again.

function showHideCalendar() {

//The location we are loading the page into.
var objID = "calendar";

//Change the current image of the minus or plus.
if (showCalendar == true){
//Show the calendar.
document.getElementById("opencloseimg").src = "images/mins.gif";
//The page we are loading.
var serverPage = "calendar.php";

anyway, the program won't go, and I get a message that "document.getElementById" is not a function. Who said it was, anyway? Why are the interpeter and I confused?

Thanks

mehh

4:06 pm on May 20, 2008 (gmt 0)

10+ Year Member



are you sure you aren't getting Java and JavaScript / JScript confused?

Baruch Menachem

9:26 pm on May 20, 2008 (gmt 0)

10+ Year Member



supposed to be javascript.

daveVk

2:29 am on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you show us were showHideCalendar is being called from, if it before the page has loaded it would explain the problem, onclick etc should be Ok.

Baruch Menachem

12:52 pm on May 21, 2008 (gmt 0)

10+ Year Member



Well, the HTML page looks like this, and it does look like a function call.... but the book had it this way....

<div id="taskbox" class="taskboxclass"></div>

<p><a href="javascript://" onclick="showHideCalendar()"><img id="opencloseimg" src="images/plus.gif" alt="" title="" style=" border: none; width: 9px; height: 9px;" /></a>
<a href="javascript://" onclick="showHideCalendar()">My Calendar</a>
</p>
<div id="calendar" style=" width : 105px; text-align : left;"></div>

daveVk

4:41 am on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anytime javascript sees "something(.. " it takes that as being a call to the function "something" or in the case of the error "getElementById" in particular the function getElementById within document. So the error indicates that document does not exist, or exists but does not contain getElementById, or exists and contains getElementById but getElementById is not a function.

The way the book has it looks Ok to me, when one of these links is clicked the function showHideCalendar will be called onclick="showHideCalendar()"

Does your code differ from the book, and does the error occur before or after clicking on the link ?