/    Sign up×
Community /Pin to ProfileBookmark

I need help!!!!! Aaaahhh!!!

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Apr 05.2003 — There you go.There were just tiny bits of mistakes.

the code below will work as you mentioned

<i>
</i>&lt;script type="text/javascript"&gt;
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;
}
}
&lt;/script&gt;
&lt;/head&gt;

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


Cheers

Khalid
Copy linkTweet thisAlerts:
@Eag_eauthorApr 05.2003 — 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. [URL=http://www.uacs.vze.com]UACS[/URL] <----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
Copy linkTweet thisAlerts:
@khalidali63Apr 05.2003 — 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.

?

Khalid
Copy linkTweet thisAlerts:
@Eag_eauthorApr 05.2003 — 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
Copy linkTweet thisAlerts:
@khalidali63Apr 05.2003 — Learning is good and you learn by making mistakes..

?

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

<i>
</i>&lt;script type="text/javascript"&gt;
&lt;!--
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;
}
//--&gt;
&lt;/script&gt;


Cheers

Khalid
×

Success!

Help @Eag_e spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...