Rikeku
09-19-2006, 01:59 PM
ok heres how javascript substrings work...
an example
< script language="Javascript">
var a1, a2, input;
a2="abcdefghij";
a1=a2.substring (2,6)
input=prompt("Password:","");
if (input==a1) {
alert("correct you may enter");
}
else {
alert:("wrong");
}
}
< /script>
now to explain how it works
the first line just tells the server that we are using javascript now...
the 2nd line tells it that the variables a1 and a2 and for the input.
the 3rd line assigns abcdefghij to the variable a2.
the 4th line assigns the substring to a1.
the other lines just setup an input prompt, if you type in the correct answer which is store in a1 then you get through if not you get an error
-
The Substring Explanation
syntax:'string'.substring(non-inclusive,value.inclusive value)
therefor it basicly is
abcdefghij.substring(2,6);
now the abcdefghij is the string and the substring will want to take some info from it. It finds out what info it needs to get from the (2,6) it tells it to take the 3rd value from the string *notice it says 2 it's none inclusive* and it takes all the values up to 6 and that includes the 6th value *notice this time it is inclusive* so our variable will have the value:-
-CDEF-
an example
< script language="Javascript">
var a1, a2, input;
a2="abcdefghij";
a1=a2.substring (2,6)
input=prompt("Password:","");
if (input==a1) {
alert("correct you may enter");
}
else {
alert:("wrong");
}
}
< /script>
now to explain how it works
the first line just tells the server that we are using javascript now...
the 2nd line tells it that the variables a1 and a2 and for the input.
the 3rd line assigns abcdefghij to the variable a2.
the 4th line assigns the substring to a1.
the other lines just setup an input prompt, if you type in the correct answer which is store in a1 then you get through if not you get an error
-
The Substring Explanation
syntax:'string'.substring(non-inclusive,value.inclusive value)
therefor it basicly is
abcdefghij.substring(2,6);
now the abcdefghij is the string and the substring will want to take some info from it. It finds out what info it needs to get from the (2,6) it tells it to take the 3rd value from the string *notice it says 2 it's none inclusive* and it takes all the values up to 6 and that includes the 6th value *notice this time it is inclusive* so our variable will have the value:-
-CDEF-