Forum Moderators: open

Message Too Old, No Replies

Javascript Errors Galore

...or why does IE think weird things are errors?

         

doodlebee

8:22 pm on Oct 16, 2005 (gmt 0)

10+ Year Member



I have a couple of javascripts that are throwing up odd errors - srictly in IE only. One of them is a third-party script, which I've already contacted to see what they can figure out...but this one was written by the designer before me. Now, it works just fine right now, but when I copied the stuff and placed it in my new design, it starts throwing up these errors. I copied it *exactly*, so I don't know why it's doing this.

So, if anyone can help me, I'd appreciate it. It's the *weirdest* things tossing out the errors, too.

The errors are:

1) Line 124 Char 33 Object doesn't support property or method Code 0

2) Line 27 Char 7 Object doesn't support property or method Code 0

And yes, it shows the errors in this order - which I thought was also odd, since the error further down the page shows up first.

The javascript:

function dosubmit() {
document.form1.Email.value = document.form0.Email.value;
savecookie(document.form1.Email.value);
document.form1.action = 'CLogin.dll?RegCustLogin';
document.form1.submit();
return false;
}

function loadcookie() {
var emailstr = "";
if( document.cookie!= "" ) {
cookArray = document.cookie.split(";");
for( i = 0; i < 4; i++ ) {
if( cookArray[i]!= null && cookArray[i]!= "") {
cookname = cookArray[i].split("=")[0];
if( cookname.indexOf("custlogin") >= 0 )
emailstr = cookArray[i].split("=")[1];
}
}
}

if( emailstr!= "" ) {
document.form0.Email.value = emailstr;
document.form1.Password.focus();
}

// This is Line 27, the letter "o" in "document" is character 7 //

else document.form0.Email.focus();
return false;
}

function savecookie(emailval) {
var expireDate = new Date;
var nYear = expireDate.getYear()+1;
if( nYear < 2000 ) nYear = 2000;
expireDate.setYear(nYear);
document.cookie = "custlogin=" + emailval + ";expires=" + expireDate.toGMTString();
return false;
}

function newcust() {
theform = document.form1;
document.location = 'clogin.dll?reg2?projectid=' + theform.inprojectid.value + '&displaytype=1' + '&runtimekey=' + theform.runkey.value;
return false;
}

The form:

<form name="form0" method="post" action="javascript:document.form1.Password.focus()">

</td></tr>
<tr><td width="125" style="text-align:right;">

<b>Email:</b>

</td><td>

<input class="form" type="text" size="25" name="Email" value="" />
<form name="form1" method="post" action="javascript:dosubmit()" />
<input type="hidden" name="inprojectid" value="13" />
<input type="hidden" name="runkey" value="" />
<input type="hidden" name="Email" value="" />

</td></tr>
<tr><td style="text-align:right;">

<b>Password:</b>

</td><td>

<input class="form" type="password" size="25" maxlength="20" name="Password" />
<input type="hidden" name="projectid" value="13" />
<script type="text/javascript">

//This is Line 124. Character 33 is the letter "t" in "document" //

if(document.form0.Email) document.form0.Email.focus();
</script>
<input type="hidden" name="Sendmail" value="0" />
</form>

</td></tr>
<tr><td colspan="2">
<input class="form" type="submit" value="Submit" onclick="dosubmit(); return false;" />
</form>
<script type="text/javascript">loadcookie();</script>

Now what's *really* odd is that I tried everything I could think of to get rid of these errors. At one point, I even erased the whole "function loadCookie()" section (which contains the Line 27 error) - and it returned the *exact* same error - even though the line was completely gone! How is that even possible? (And yes, I double-checked to be sure I saved and uploaded the file - still did it)

Can anyone take a glance and see what's up with this? I'd really appreciate the help :)

Bernard Marx

8:38 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There appear to be 2 forms, with one nested inside the other.
The inner one is also XHTML-style self-closing <form ... />. What gives?

doodlebee

9:01 pm on Oct 16, 2005 (gmt 0)

10+ Year Member



No kidding.

I haven't gone through and checked the old designer's form code - I've just been trying to get the javascript to stop popping up the error messages.

Basically, I just copied exactly what the old designer had, I just put what script inof she had within *my* tables (as hers were *way* weird).

I'll fix the form tag issues and see what happens - I never even noticed that...just copied and pasted!

Bernard Marx

9:43 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a fair bit of "way weird" reflected in there - IMHO. I have no idea what's going on. The form also appears to rely on JS being enabled to the extent that it won't be sent if it isn't enabled (This might be OK; I don't know the context).

A thorough re-write might be the order of the day.

Bernard Marx

9:47 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and it returned the *exact* same error - even though the line was completely gone! How is that even possible?

I think you are counting the lines from the wrong starting point.

doodlebee

10:45 pm on Oct 16, 2005 (gmt 0)

10+ Year Member



I'd agree with the idea of a thorough rewrite, but I can't write javscript...never have.

As for counting from the wrong starting point, I'd thought that, too. But when I changed starting points, or deleted lines to see if the error message would bring it up a bit to change the line number, it always pointed to those two spots, every time.

I'm not too worried about it - I'm sure something'll get figured out. But it'd be nice to know why it's doing this - I have another script that's throwing out an odd error - it'll go away only if I remove the "a" from my <a href=" tag. Makes the script error go away, but renders the link useless.

kaled

12:15 am on Oct 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript is interpreted so, assuming it is syntactically ok, errors are thrown in the order of execution - it's not weird.

Kaled.