JavaScript - Captcha
When user answers correctly (on key up AND key down), text field (CAPTCH) should become disabled, and span of id=correct should change to "√ Correct"..
What is wrong with my code? No errors are returned. It just doesnt work. Please excuse my novice knowledge of javascript. Im just starting. Could someone please explain to me my error rather than solve it? I wanna learn, not be handed the answer. Thanks in advance, Robert PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Captcha</title> <script type="text/javascript"> var x = 44; var y = document.getElementById('CAPTCHA'); function correct() { if (y = x.value) { document.getElementById("correct").innerHTML = "√ Correct"; document.getElementById("CAPTCHA").innerHTML.disabled = "disabled"; } else {} } </script> </head> <body> 11 x 4 = <input type="text" id="CAPTCHA" onkeyup="correct()" onkeydown="correct()" /> <span id="correct">.....</span> </body> </html> Similar TutorialsHello, I was using http://www.captcha.cc to generate free and easy captcha for my forms. None of them are working today. I don't know if the site has been removed or it is a temporary thing. Does anyone know? Do you know of a really easy and free captcha generator I can use instead? Thank you for your help. Also, we cannot use PHP. hello, I got this javascript code to avoid bots to fill out with trash the forms I have in my website: <script type="text/javascript"> var a = Math.ceil(Math.random() * 10); var b = Math.ceil(Math.random() * 10); var c = a + b function DrawBotBoot() { document.write("Cuanto es "+ a + " + " + b +"? "); document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>"); } function ValidBotBoot(){ var d = document.getElementById('BotBootInput').value; if (d == c) return true; return false; } </script> <P>Are you human?<br /> <script type="text/javascript">DrawBotBoot()</script> <P> <INPUT id="Button1" name="SUBMIT" TYPE="SUBMIT" VALUE="ENVIAR" onclick="alert(ValidBotBoot());"/> <INPUT name="RESET" TYPE="RESET" VALUE="BORRAR"> My problem is that the form sends itself even if you dont type the correct answer, I would like to Validate first and then allow me to send the form after validation. You can see the form he http://www.futuros.com/mercados_calientes.html feel free to play with it, i know is the only way to actually see what i'm trying to accomplish. Thanks, Alan Hello, When I have email validation and captcha in the same form, simply passing the captcha allows the form to be sent without an email address. When I remove the captcha, the form will not send without the email address. I want to have both. What am I missing? http://jaxpubliclibrary.org/lib/websiteform-test.html Code: <script> function validateForm() { var x=document.forms["WebsiteQuestion"]["Email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } function clearForms() { var i; for (i = 0; (i < document.forms.length); i++) { document.forms[i].reset(); } } </script> Code: <div align="center"> <script language="javascript" src="http://www.captcha.cc/cap.js?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" type="text/javascript"> </script> <input type=hidden name=cap_h id=cap_h value=""> <img border=1 id=cap_i src="http://www.captcha.cc/img.cgi?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" align=middle><img align=middle style="margin-left: 4px;" id=cap_r onload="return cap_showReload(event);" src="http://www.captcha.cc/blank.png"><br> <input id=cap_t name=cap_t type=text value="" style="margin-top:4px;"> <input type=submit value="Submit Form" onclick="return cap_valid(event);"> </div> I appreciate any help. Thank you, Elbee Hello, I've been having a maddening issue with a CAPTCHA javascript math problem validation blocking the correct information from going to my contact form. I feel like I am overlooking something obvious. Basically I just want to create a simple javascript function that when the incorrect CAPTCHA code is entered an alert comes up saying "incorrect code" and then the form is not sent. The way it is working now, the form is passing through (due to document.write) but it is NOT allowing the PHP script to execute correctly, probably because document.write is bypassing the fields somehow. When I remove "return false;" the form goes through all the time, even after the alert comes up. When I keep "return false;" it goes through but the message is not sent correctly. Is there an easy way to make this work? Here is the javascript code: Code: <script type="text/javascript"> var a = Math.ceil(Math.random() * 10); var b = Math.ceil(Math.random() * 10); var c = a + b; function DrawBotBoot() { document.write("What is "+ a + " + " + b +"? "); document.write(" <input type='text' id='BotBootInput' name='Math' style='background-image: url(images/main/footer_math_problem_bknd.gif); width: 32px; height: 18px; padding: 5px; border: none; color: #fff;' /> "); } function ValidBotBoot(){ var d = document.getElementById('BotBootInput').value; if (d == c) { window.location = "sendmail.php";} else { alert("Incorrect CAPTCHA code"); } } </script> And here is the HTML form: Code: <form method="POST" action="sendmail.php"> <label for="FirstName"><p style="width: 120px; line-height: 0.4em;">Name:</p> </label> <input type="text" id="FirstName" name="FirstName" style="background-image: url(images/main/footer_text_field.gif); border: none; height: 26px; width: 216px; padding-left: 5px; color: #fff;" /> <label for="Emailaddress"><p style="width: 120px; line-height: 0.4em;">Email:</p></label> <input type="text" id="Emailaddress" name="Emailaddress" style="background-image: url(images/main/footer_text_field.gif); border: none; height: 26px; width: 216px; padding-left: 5px; color: #fff;" /> <legend><p style="line-height: 0.4em;">Your Message:</p></legend> <textarea name="QuestionComment" id="txt" style="background-image: url(images/main/footer_text_area.gif); width: 211px; height: 73px; padding: 5px; color: #fff; border: none;"></textarea><br /> <p style="width: 221px;"><script type="text/javascript">DrawBotBoot()</script> <input type="image" name="submit" id="submit" value="Submit" src="images/main/footer_submit.gif" height="28" align="right" onclick="ValidBotBoot(); return false;" /> </p> </form> So we need script like that http://userscripts.org/scripts/show/38736 But i dont know how to make it to that captcha http://one.lt/captcha Any1 have idea? :SSSSSSSSS hi everyone, Here's part of the codes I got from our website. Right now, when someone wants to register on our website, they have to put into the Captcha after they finish all the other information. If the captcha is empty, there would be an alert; if it's wrong, the page would be refreshed, and there would be another alert, and at the same time, all the information would be lost and they have to fill them again. Now the question is, how can I stop the page refreshing itself? All I need is an alert and then you could retype the captcha without losing the other information. Thank you in advance for your advice! <script type="text/javascript"> function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); } function validateForm() { var okSoFar=true with (document.practitioner_profile) { if (firstname.value=="" && okSoFar) { okSoFar=false alert("Please enter your first name.") firstname.focus() } if (lastname.value=="" && okSoFar) { okSoFar=false alert("Please enter your last name.") lastname.focus() } //some other things here... if (verify_code.value=="" && okSoFar) { okSoFar=false alert("Please enter your security code.") verify_code.focus() } if (okSoFar==true) submit(); } } //here's the submit button in the html code, <div class="practsubmit"> <div class="signupform"><h4>* Security Code:</h4> <p>Please type in what you see in the box below and press submit. Characters are case-sensitive.</p></div> <div class="signupform"><img id="captcha" src="index.php?option=com_egbcaptcha&width=150&height=50&characters=5" /><br /><input id="verify_code" name="verify_code" type="text" /></div> <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> <input type="reset" class="button" value="Clear" name="clear"> </div> |