Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to stop refreshing the page when captcha is wrong

    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&amp;width=150&amp;height=50&amp;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()">&nbsp;<input type="reset" class="button" value="Clear" name="clear">
    </div>

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,758
    Thanks
    41
    Thanked 191 Times in 190 Posts
    would need to see more code most likely... adding return false; should keep it from submitting and clearing all of your stuff out- need to have someone better @ javasccript look at it... none-the-less you are posting in the Java section, not the javascript section

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by alykins View Post
    would need to see more code most likely... adding return false; should keep it from submitting and clearing all of your stuff out- need to have someone better @ javasccript look at it... none-the-less you are posting in the Java section, not the javascript section
    Yes indeed, moving from Java forum to Javascript forum.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    onclick="return validateCaptcha(); return validateForm()">

    where validateCaptcha() is a separate function to check the captcha and simply raise an alert if invalid.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •