Welcome to WebmasterWorld Guest from 54.226.146.15

Forum Moderators: open

Message Too Old, No Replies

JavaScript is a pain

Mostly cause I'm not used to coding in it. HELP!

     

circuitjump

8:34 pm on Feb 1, 2002 (gmt 0)

10+ Year Member



Hi all,
Small problem here.
I want to have the variable i add one for every if statement it goes through.
But it keeps giving me 1 and I just don't know what I'm doing wrong.

Can anybody help?

<script language="JavaScript">
var i = 0;
if ("200107100000" && "200107150000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200107100000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200107150000");
document.write ("</td>");
document.write ("</tr>");

}
if ("200108170000" && "200108140000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200108170000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200108140000");
document.write ("</td>");
document.write ("</tr>");

}
if ("200109050000" && "200109070000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200109050000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200109070000");
document.write ("</td>");
document.write ("</tr>");

}
</script>

bmcgee

12:07 am on Feb 2, 2002 (gmt 0)

10+ Year Member



you need to change the line "i = +1" to read either:
i = i + 1
or
i += 1 (I think this works in Javascript).

Your line of code is simply assigning "positive 1" to the i variable during each iteration.

justa

11:13 pm on Feb 3, 2002 (gmt 0)

10+ Year Member



i=++1
should also work.

IanKelley

1:38 am on Feb 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as well i++ :-)

circuitjump

6:56 pm on Feb 4, 2002 (gmt 0)

10+ Year Member



Hi all,

Got that part to work by using
i = i+1;

Thanks to all, it worked. :)

justa, I tried it like so
i = ++1;

Cause thats how I do it in PHP which is what I'm mostly used to. But no cigar in JS. But thanks for the help anyways.

:)

Thank you all

 

Featured Threads

Hot Threads This Week

Hot Threads This Month