homepage Welcome to WebmasterWorld Guest from 54.237.245.159
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript is a pain
Mostly cause I'm not used to coding in it. HELP!
circuitjump




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

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




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

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




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

i=++1
should also work.

IanKelley




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

as well i++ :-)

circuitjump




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved