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 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Javascript/php form validation

    Hello people!

    I'm new to coding and really need some help.
    I want javascript to validate a form before submitting.

    Form is named "formoklada"
    I want to validate these things:
    1st in form field named "Log" I want the users to be able to enter only one number between 1 and 10 (including 1 and 10)
    2nd I want that they check one of the 5 buttons named "Tip"
    3rd I want to limit submission possibility with date and time. Expiration date and time for the form submission are in 2 fields named "Date" and "Time" of the form.

    When the form is not properly filled I want alert to pop up and warn.

    I was struggling with this for three days now and am going nuts. It's waaaay too complicated for me so I gave up.

    If there is a kind sole willing to help, please do so! I read all the tutorials for javascript on the net and cant figure those things out. Need more time to learn, but I need this script urgently!

    Thank you very much!
    Last edited by deki; 07-14-2009 at 07:09 PM.

  • #2
    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
    Despite the similar sounding names, Java is not the same as javascript.
    Moving from Java forum to javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #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
    If there is a kind sole willing to help, Something fishy there!


    1)
    Code:
    <form name = "myform">
    Enter a number from 1 to 10 <input type = "text" name = "log" id = "log" size = "2" maxlength = "2" onblur = "chknum()">
    </form>
    
    <script type = "text/javascript">
    function chknum() {
    var num = document.myform.log.value;
    num = num.replace(/[^0-9]/g,"");
    if ((num <1) || (num >10)) {
    alert ("You must enter a number from 1 -10");
    document.myform.log.value = "";
    document.myform.log.focus(); 
    }
    
    }
    
    </script>
    2.

    You cannot "check" a button, nor may multiple form elements have the same name. Do you mean radio buttons? Or checkboxes?


    3)

    You must give more information. Do you mean that the form may not be submitted if the specified date and time have passed? If so, what is the format of the date and time? DD/MM/YYYY or what? But in principle:-


    Code:
    <input type = "submit" name = "fsub" id = "fsub" value = "Submit the form">
    
    <script type = "text/javascript">
    var final = new Date(2009,06,14,14,00,00);   // 14th July 2009 1400 hrs.
    var now = new Date();
    if (final < now) {
    alert ("You are too late to submit this form!")
    document.getElementById("fsub").disabled = true;
    }
    
    </script>
    Note that Javascript can be disabled by the user!



    “I am so clever that sometimes I don't understand a single word of what I am saying.” - Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)
    Last edited by Philip M; 07-15-2009 at 09:27 AM.

  • Users who have thanked Philip M for this post:

    deki (07-15-2009)

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    @ Fou-Lu
    Sorry! I know very little about programming, but I knew that I guess I was clumsy... Sorry again!

    @ Philip M
    I'm very thankful for all of this!!! I actually didn't expect this kind of help So quickly and accurate!

    In the matter no.2 I really meant radio buttons... again, clumsy me, sorry!

    So if you could help me only just with this I'd be very grateful!

  • #5
    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
    but I need this script urgently! Does that mean homework? If so, that is as far as I can go.


    Code:
    <form name = "myform">
    1 <input type = "radio" name = "tip">
    2 <input type = "radio" name = "tip">
    3 <input type = "radio" name = "tip">
    4 <input type = "radio" name = "tip">
    5 <input type = "radio" name = "tip">
    <br><br>
    <input type = "submit" name = "fsub" id = "fsub" value = "Submit the form" onclick = "return checkrads()">
    </form>
    
    <script type = "text/javascript">
    function checkrads() {
    var unchecked = 0;
    for (var i =0; i<document.myform.tip.length; i++) {
    if (document.myform.tip[i].checked) {
    unchecked = 1;
    }
    }
    if (unchecked == 0) {
    alert ("You must select one of the radio buttons!  ");
    return false;
    }
    }
    
    </script>
    Last edited by Philip M; 07-15-2009 at 09:30 AM.

  • Users who have thanked Philip M for this post:

    deki (07-15-2009)

  • #6
    New Coder
    Join Date
    Jul 2009
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    No it's not a homework, it's kind of a work/job I'm doing.

    I haven't been able to test scripts you posted yet but I believe they will work.

    One more thing... how do I combine those functions under one onClick="validation()"... or do I have to use more functions onclick?

  • #7
    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
    Quote Originally Posted by deki View Post
    will work.

    One more thing... how do I combine those functions under one onClick="validation()"... or do I have to use more functions onclick?
    onclick = "function1(); function2(); function3()"

    or perhaps

    onclick = "return (function1() && function2())"

    if both functions msut return true.

  • #8
    Banned
    Join Date
    Jun 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript/php form validation

    sir i read the forum of username validation using php ajax and javascript.


    The code which u gave was interesting...

    But i tried out in my system...

    It is not reporting anything about username whether it is availabe or not..

    I would not trace out the error also..

  • #9
    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
    Quote Originally Posted by gkumar View Post
    sir i read the forum of username validation using php ajax and javascript.


    The code which u gave was interesting...

    But i tried out in my system...

    It is not reporting anything about username whether it is availabe or not..

    I would not trace out the error also..

    Sorry - I haven't a clue what you are talking about. There is nothing about "username" in this thread.
    You seem very prone to regurgitate your undigested thoughts over this group.


  •  

    Posting Permissions

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