PDA

View Full Version : Please help, I'm new here!


waicten
12-14-2002, 10:49 AM
I just want to know how to put an "if then else" under here, please help.

I mean, if (1<x<1000) goto Check1.js
if (1001<x<2000) goto Check2.js
.........
........

What I did below will run all the .js files, it take forever.
Thanks for your help.


<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript" src="Check1.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check2.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check3.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check4.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check5.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check6.js">
checkpoints x,y
</script>

<script language="JavaScript" src="Check7.js">
checkpoints x,y
</script>

Admin warning-- Please use a more descriptive subject for your thread next time. See: http://www.codingforums.com/postguide.htm

whammy
12-14-2002, 11:32 AM
are you using the same function in all of the included files?

krycek
12-14-2002, 11:48 AM
I am not sure exactly what you are trying to do but I am pretty sure you are approaching the whole thing the wrong way.

In JavaScript, an IF... THEN... ELSE... statement is written like this:


if (condition) {
action;
} else if (condition) {
action;
} else {
action;
}


...where 'condition' is something that, when evaluated, is true.

For example:


if (x > 0 && x <=1000) {
alert("too low!");
} else if (x > 1000 && x < 2000) {
alert("too high!");
} else {
alert("hey that's not valid!");
}


I dunno what your checkpoint stuff is, but I think you have the wrong idea about the script tags.

Use <script src="myscript.js" language="JavaScript" type="text/javascript"></script> when you need to include a script that is in a separate file.

Use <script language="JavaScript" type="text/javascript"></script> for a script in the current document, i.e. without the src attribute. Then put your code between the script tags, like you did with your checkpoint thing.

e.g.


<script language="JavaScript" type="text/javascript">
if (x > 0 && x <=1000) {
alert("too low!");
} else if (x > 1000 && x < 2000) {
alert("too high!");
} else {
alert("hey that's not valid!");
}
</script>


I assume that checkpoints is a function and that x and y are variables, but you're gonna have to tell us what you want to do before anyone can help you with that. :)

::] krycek [::

whammy
12-14-2002, 12:01 PM
FYI, language="javascript" is deprecated in XHTML, in favor of using (for example in an HTML page):

<script type="text/javascript">
<!--
// -->
</script>

To include an external javascript library, it would be:

<script type="text/javascript" src="whatever.js"></script>

:)

krycek
12-14-2002, 12:17 PM
DOH! :rolleyes:

Sorry whammy - you are of course correct, I only ever use external js files nowadays and so the html commenting bit slipped my mind :D

...glad to know there's always someone looking over my shoulder just in case I make a mistake!!! :p

::] krycek [::

whammy
12-14-2002, 12:38 PM
Not really a mistake, I just point these things out when I can as a reminder... :)

brothercake
12-16-2002, 09:11 PM
Originally posted by whammy
FYI, language="javascript" is deprecated in XHTML, in favor of using (for example in an HTML page):

<snip/>

To include an external javascript library, it would be:

<script type="text/javascript" src="whatever.js"></script>

That's not necessarily good advice. If - for example - you use javascript 1.2 methods and you run it in a browser with lower capabily (such as Netscape 3) then you will get javascript errors - even if you've sniffed for a specifically excluded netscape 3.

The language attribute is essential - you should use them both:

<script language="javascript1.2" type="text/javascript" src="whatever.js"></script>



Of course ... if you don't care about errors in netscape 3 :rolleyes:

whammy
12-16-2002, 11:30 PM
My philosophy is this - if anyone's still using Netscape 3 (or ANY browser that old), they most likely see errors everywhere they go, and should have upgraded by now anyway. I'm sure they're used to it.

I'd much rather support standards (and have code that validates) than hack the heck out of my code to support a browser that is over 7 years old. :)