Forum Moderators: open

Message Too Old, No Replies

JavaScript Returning Error

         

J_n_b

4:44 pm on Jun 6, 2006 (gmt 0)

10+ Year Member



Hi,
I am making a website that has four Javascript based tests. Nothing happens.
Here is the code:

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source! http://javascript.internet.com -->

<!-- Begin
function calc() {

first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {
letter1=first.substring(Count,Count+1);
if (letter1=='L') LoveCount+=2;
if (letter1=='O') LoveCount+=2;
if (letter1=='V') LoveCount+=2;
if (letter1=='E') LoveCount+=2;
if (letter1=='Y') LoveCount+=3;
if (letter1=='O') LoveCount+=1;
if (letter1=='U') LoveCount+=3;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='L') LoveCount+=2;
if (letter2=='O') LoveCount+=2;
if (letter2=='V') LoveCount+=2;
if (letter2=='E') LoveCount+=2;
if (letter2=='Y') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3;
}

amount=0;
if (LoveCount> 0) amount= 5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)

if (firstlength==0 ¦¦ secondlength==0) amount= "Err";
if (amount < 0) amount= 0;
if (amount >99) amount=99;

document.loveform.output.value=amount+"%";
}
// End -->
</script>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name=loveform>
<input value="Bill Clinton" name="name1" type="text" size="20"> +
<input value="Monica Lewinsky" name="name2" type="text" size="20"> =
<input value="" name="output" type="text" size="6">
<br>
<br>
<input value="Calculate!" name="calculate" type="button" value="calculate" onclick="calc()">
</form>

If you could say what is wrong. I am thinking the code is right but it gets changed maby by my WYSIWYG editor?
Many thanks,
JNB

[edited by: DrDoc at 6:49 pm (utc) on June 7, 2006]
[edit reason] removed URL [/edit]

Fotiman

5:49 pm on Jun 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your HTML document is missing opening and closing html element. It's also missing the end tag for head and body. If you fix those, it works. Note, this forum replaces the pipe character with weird ones, so be sure to change ¦¦ back to the correct characters:


<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source! [javascript.internet.com...] -->

<!-- Begin
function calc() {

first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {
letter1=first.substring(Count,Count+1);
if (letter1=='L') LoveCount+=2;
if (letter1=='O') LoveCount+=2;
if (letter1=='V') LoveCount+=2;
if (letter1=='E') LoveCount+=2;
if (letter1=='Y') LoveCount+=3;
if (letter1=='O') LoveCount+=1;
if (letter1=='U') LoveCount+=3;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='L') LoveCount+=2;
if (letter2=='O') LoveCount+=2;
if (letter2=='V') LoveCount+=2;
if (letter2=='E') LoveCount+=2;
if (letter2=='Y') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3;
}

amount=0;
if (LoveCount> 0) amount= 5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)

if (firstlength==0 ¦¦ secondlength==0) amount= "Err";
if (amount < 0) amount= 0;
if (amount >99) amount=99;

document.loveform.output.value=amount+"%";
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name=loveform>
<input value="Bill Clinton" name="name1" type="text" size="20"> +
<input value="Monica Lewinsky" name="name2" type="text" size="20"> =
<input value="" name="output" type="text" size="6">
<br>
<br>
<input value="Calculate!" name="calculate" type="button" value="calculate"

onclick="calc()">
</form>

</BODY>
</HTML>

J_n_b

2:51 pm on Jun 7, 2006 (gmt 0)

10+ Year Member



Thanks :)
But i already had that, i just posted the code i was trying to get to work. I would post the full page code but it's too long. Anyone have anymore suggestions. Check the site in IE for an error report.

Fotiman

2:55 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Perhaps you didn't see the part of my post where I wrote:

If you fix those, it works.

The above example that I posted works for both IE and Firefox. What problem are you having?

Fotiman

2:58 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PS - The Terms of Service of this site do not permit posting URLs. They encourage you to post your code examples instead.

Fotiman

3:04 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your problem is that on your page you have 2 opening tags that have <form name=loveform>.

For future reference, please post your actual code instead of URLs. Had you posted your code, I would not have misunderstood your problem.

J_n_b

6:43 pm on Jun 7, 2006 (gmt 0)

10+ Year Member



I took the out and it still doesn't work. IE is still reporting the same error. THanks

Fotiman

7:29 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your first form closing tag looks like this:

</ form>

Change that to:

</form>

And it will work.

J_n_b

5:50 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



No thats for the dropdown menu, and thats not the problem. It's to main javascript in the middle.

Fotiman

7:46 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm telling you, fix that. It's the cause of your problem.

Your browser is not seeing that first form as being closed, therefore your second form is not recognized, which is why you get the error. Fix that first closing tag, and your page works. I have copied your source code and tried this locally and verified that that is the problem.

J_n_b

4:08 pm on Jun 10, 2006 (gmt 0)

10+ Year Member



I fixed that and it has make all the javascript on my site work... exept the love test! You helped alot but it still isn't working :s (The other tests are)