Click to See Complete Forum and Search --> : I need help!!!!! Aaaahhh!!!


Eag|e
04-05-2003, 12:06 AM
Ok, I have tried and tried and tried! This code I wrote keeps on giving me errors! What I need to do with it is have it check a text box for a word, and if the word matches the variable I made then it sends the form, otherwise it doesn't and displays an error box saying it was an incorrect code. Here is the code, someone please help me.

<SCRIPT language = "JavaScript">
var code = "check";
var get_code = document.f1.code.value;
function check_code()
{
if (code == get_code)
{
return true;
}
else
{
return false;
window.alert("Incorrect recruitment code!");
}
}
</SCRIPT>

For clarification, f1 is the form name, code is the textbox name. Someone please help. Thanks ~ EaG|E

khalidali63
04-05-2003, 12:24 AM
There you go.There were just tiny bits of mistakes.

the code below will work as you mentioned


<script type="text/javascript">
var code = "check";
function check_code(){
var get_code = document.form1.code.value;
if (code == get_code){
return true;
}else{
alert("Incorrect recruitment code!");
return false;
}
}
</script>
</head>

<body>
<form name="form1" action="" onsubmit="return check_code();">
<input type="Text" name="code"/>
<input type="Submit" value="process"/>
</form>


Cheers

Khalid

Eag|e
04-05-2003, 11:23 AM
Alright, it is still giving me the same error. When I hit submit it says "Object Expected" and sends it anyways without the correct code in there. UACS (http://www.uacs.vze.com) <----go there then go to Join and at the bottom of the form is where the code (Recruitment Code) is supposed to be entered. Try it out for yourself on there, but it gives me that error and still sends in. The code is "check" so try it out yourself. ~ EaG|E

khalidali63
04-05-2003, 11:28 AM
You did make changes to the code I posted above.

onSubmit =" check_it();" is wrong...

see the code is setting return type to false if it doesnt match the word,therefore you have to get the return type of the method in here,
it should be like this

onSubmit ="return check_it();"

I hope this solves it.

:D

Khalid

Eag|e
04-05-2003, 02:33 PM
It's not that I changed it, I looked at it and didn't notice the return thing so I didn't change it...but it is still giving me the Object Expected error on the line that the form starts on... I like never use JavaScript, but I'm kinda trying to learn it cuz it is useful sometimes, but from the looks of it, there is no errors in your code...I have no clue what is wrong with it. If you somehow figure it out, let me know, otherwise thanks for trying man. Peace ~ EaG|E

khalidali63
04-05-2003, 02:48 PM
Learning is good and you learn by making mistakes..

:D

take a look..replace your javascript code with this piece of code


<script type="text/javascript">
<!--
var code = "check";
function check_code(){
var get_code = document.form1.code.value;
if (code == get_code){
return true;
}else{
alert("Incorrect recruitment code!");
return false;
}
return false;
}
//-->
</script>


Cheers

Khalid