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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help for Developing Script

    In my form there are two text fields so when i navigate from 1st textfield to 2nd textfield a alert box needed to be displayed validating the data in 1st textfield like it should be numbers . The checking should be done strictly before submission of the form and while during navigating.
    Thankx in advance

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,313
    Thanks
    23
    Thanked 612 Times in 611 Posts

  • #3
    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
    Code:
    <form>
    <input type == "text" name = "txt1" onblur = "validate(this)">
    <br>
    <input type == "text" name = "txt2" >
    </form>
    
    <script type = "text/javascript">
    function validate(which) {
    var val = which.value;
    if (/[^0-9]/g.test(val)) {
    alert ("This box may contain integer numbers only");
    document.forms[0].txt1.value = "";
    setTimeout("document.forms[0].txt1.focus()", 25);
    }
    }
    </script>

    Quizmaster: A barrister's wig is traditionally made from the hair of which animal?
    Contestant: A goat

    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
    •