Click to See Complete Forum and Search --> : Entry Code Validation
eXploDe
11-16-2003, 03:40 PM
Hiya,
I am having trouble with a JS which I want to check if a code printed out by one script, has been entered correctly by a user into a text box.
<script language="JavaScript" type="text/javascript">
<!--
var photos = 9;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % photos;
ad +=1;
if (ad==1) {
alt=3957;
}
if (ad==2) {
alt=2395;
<snip> ...
}
if (ad==9) {
alt=3465;
document.write(' ' + alt + ' \ ');
// -->
<!--
function validate()
{
if ((!document.example2.naming.value==' ' + alt + ' \ '))
{
alert ("Code Incorrect, Please read disclaimer!")
return false
}
}
//-->
</script>
As you can probably see, the first JS code takes a 4 digit code from a list of, then prints it, the user is then supposed to enter the code into a text box, which the second function "validate()" then checks. I know the first JS code is correct because it prints out the 4 digit code, but the second function doesnt seem to check it correctly,
Any help greatly appreciated.
Chris
if (document.example2.naming.value!=' '+alt+' \ ')
[J]ona
eXploDe
11-17-2003, 03:48 AM
still seems not to work, I forgot to mention I am calling it using "return validate()"
i.e
<form method="POST" action="<href-here>" name="code" onsubmit="return validate()">
<input type="text" name="box" size="20">
<input type="submit" value="Submit" onsubmit="return validate()" name="B1">
cheers, chris
var alt;
/* Your first function goes here */
function validate(){
if(document.code.box.value!=' ' + alt + ' \ '){
alert ("Code Incorrect, Please read disclaimer!")
return false;
}
}
[J]ona
eXploDe
11-17-2003, 06:15 PM
Ok, that is pretty much it. the only problem I have now, is even when the right code is entered, it still alerts "Code Incorrect, Please read disclaimer". I had a go at fiddling with code myself, but it doesnt seem to have worked. this is the code that ended up with :
<script>
<!--
var alt;
/* Your first function goes here */
function validate(){
if(document.code.box.value!=' ' + alt + ' \ ')
{
alert ("Code Incorrect, Please read disclaimer!")
return false
}
else
{
return true
}
}
//-->
</script>
Plz point me in the right direction,
Thanks, Chris
<script>
<!--
var alt;
var photos = 9;
var now = new Date();
var sec = now.getSeconds();
var ad = sec % photos;
ad +=1;
if (ad==1) {
alt=3957;
}
if (ad==2) {
alt=2395;
<snip> ...
}
if (ad==9) {
alt=3465;
document.write(' ' + alt + ' \ ');
function validate(){
if(document.code.box.value!=' ' + alt + ' \ ')
{
alert ("Code Incorrect, Please read disclaimer!")
return false
}
else
{
return true
}
}
//-->
</script>
[J]ona
eXploDe
11-17-2003, 06:32 PM
sorry to say but there is still code errors, it does not display any code on the page now & keeps giving a JS error "expected "}"",
any ideas? chris
<script type="text/javascript"><!--
var alt = 0;
var photos = 9;
var now = new Date();
var sec = now.getSeconds();
var ad = sec % photos;
ad +=1;
if(ad==1) {alt=3957;}
if(ad==2) {alt=2395;}
if(ad==9) {
alt=3465;
document.write(' '+alt+' \ ');
}
function validate(){
if(document.code.box.value!=' '+alt+' \ '){
alert("Code Incorrect, Please read disclaimer!");
return false;
} else {return true;}
}
//-->
</script>
[J]ona
eXploDe
11-17-2003, 06:47 PM
unfortunatly it still does not seem to work, sorry bout this,
chris
Originally posted by eXploDe
unfortunatly it still does not seem to work, sorry bout this,
Are you getting an error?
[J]ona
eXploDe
11-17-2003, 06:55 PM
If I have the script like this it simply does not display the actual code needed to enter:
<script type="text/javascript">
<!--
var alt = 0;
var photos = 9;
var now = new Date();
var sec = now.getSeconds();
var ad = sec % photos;
ad +=1;
if (ad==1) {alt=3957;}
if (ad==2) {alt=2395;}
if (ad==3) {alt=2645;}
if (ad==4) {alt=1029;}
if (ad==5) {alt=2048;}
if (ad==6) {alt=9683;}
if (ad==7) {alt=3948;}
if (ad==8) {alt=1389;}
if (ad==9) {
alt=3465;
document.write(' '+alt+' \ ');
}
function validate(){
if(document.code.box.value!=' '+alt+' \ '){
alert("Code Incorrect, Please read disclaimer!");
return false;
} else {return true;}
}
//-->
</script>
You will need to include the actual HTML as well. The JavaScript is only the functions that process that data entered in the HTML form.
[J]ona
eXploDe
11-17-2003, 07:06 PM
ok :
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--
var alt = 0;
var photos = 9;
var now = new Date();
var sec = now.getSeconds();
var ad = sec % photos;
ad +=1;
if (ad==1) {alt=3957;}
if (ad==2) {alt=2395;}
if (ad==3) {alt=2645;}
if (ad==4) {alt=1029;}
if (ad==5) {alt=2048;}
if (ad==6) {alt=9683;}
if (ad==7) {alt=3948;}
if (ad==8) {alt=1389;}
if (ad==9) {
alt=3465;
document.write(' '+alt+' \ ');
}
function validate(){
if(document.code.box.value!=' '+alt+' \ '){
alert("Code Incorrect, Please read disclaimer!");
return false;
} else {return true;}
}
//-->
</script>
<p><form method="POST" action="http://nschat.com/~phreeze/index-frameset.html" name="code" onsubmit="return validate()">
<input type="text" name="box" size="20"><input type="submit" value="Submit" onsubmit="return validate()" name="B1">
</form>
</body>
</html>
eXploDe
11-17-2003, 07:12 PM
no, it doesnt display the code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
var alt = 0;
var photos = 9;
var now = new Date();
var sec = now.getSeconds();
var ad = sec % photos;
ad +=1;
function adCheck(){
if (ad==1) {alt=3957;}
if (ad==2) {alt=2395;}
if (ad==3) {alt=2645;}
if (ad==4) {alt=1029;}
if (ad==5) {alt=2048;}
if (ad==6) {alt=9683;}
if (ad==7) {alt=3948;}
if (ad==8) {alt=1389;}
if (ad==9) {alt=3465;}
document.write(alt);
}
function validate(){
if(document.code.box.value!=alt){
alert("Code Incorrect, Please read disclaimer!");
return false;
} else {return true;}
}
//-->
</script>
</head>
<body>
<p><script type="text/javascript"><!--
adCheck();
//--></script></p>
<form method="POST" action="http://nschat.com/~phreeze/index-frameset.html" name="code" onsubmit="return validate();"><div>
<p><input type="text" name="box" size="20">
<input type="submit" value="Submit" onsubmit="return validate()" name="B1"></p>
</div></form>
</body></html>
[J]ona
eXploDe
11-17-2003, 07:25 PM
Thanks ever so much, This problem has been annpyong me for a while now & I'm glad its sorted. I see from the web logs you've taken a quick look at it, it isnt quite finished yet, unfortunatly time is against me with work & all.
Once again, Thanks, Chris