I've made a basic captcha function that generates a random 5-digit code that the user has to input in order to prove that they are human. Basic stuff. However, I want it to load a javascript function to validate the captcha before the form is funny submitted.
Here's the Javascript:
<script type='text/javascript'>
function check(form){
if(form.cap.value != <?php echo($c); ?>){
alert("You must enter the captcha code.");
form.cap.focus();
return true;
} else {
return true;
}
}
</script>
The correct captcha string is $c, by the way. Here's my form HTML:
<form name="upf" enctype="multipart/form-data" action=\"\" method="post">
..Other input shit, blah blah..
<input name="cap" type="text" maxlength="5"/>
<input type="submit" value="Upload" name="upload" onclick="return check(document.upf);"/>
</form>
Now, I don't know the least bit of Javascript, at all, so for all I know this could be a very simple problem. I also don't know if the way I'm implementing the PHP variable into the function is correct.