SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $('Submit').click(function) before goes to php

    <form action="complited.php" method="post">
    <input type="text" name="test" />
    <input type="text" name="test2" />
    <input type="submit" />
    </form>

    Please tell me how I can check on submit click if any text field is empty before it goes to complited.php with jquery. I want to check on click if any name is empty. If it is, than var checking=1 else continue with complited.php.

    Thank you

  2. #2
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need a javascript submit form too.

    Hope some one can help us.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so far I know I need to create function which will be executed onsubmit. But the problem I have is how to make if isGood = false { alert("Please fill all your data") before sending user to php file. Now it send user there in any way, either if isGood=false or true.


    <form action="complited.php" method="post" onsubmit="validate();">
    <input type="text" name="test" id="test" />
    <span id='testVal'></span>
    <input type="text" name="test2" id="test2" />
    <span id='test2Val'></span>
    <input type="submit" />
    </form>

    <script>
    function validate() {
    var isGood = true;

    //validate test
    if(document.getElementById('test').value=='') {
    isGood = false;
    document.getElementById('testVal').InnerHTML = 'required';
    }

    //validate test2
    if(document.getElementById('test2').value=="") {
    isGood = false;
    document.getElementById('test2Val').InnerHTML = 'required';
    }

    //return true or false
    return isGood;
    }

  4. #4
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey mate

    it should be

    <form action="complited.php" method="post" onsubmit="return validate()">
    ...
    </form>

  5. #5
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $("#myform").submit( function() { 
      return $(
    "input"this).val().length 0
    } ); 


Bookmarks

Posting Permissions

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