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 Coder
    Join Date
    Mar 2008
    Posts
    88
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Simple form validation question

    I have a form that is submitted by a button that calls an ajax request. I want that same button to have another onclick event that checks the form is valid. How do i do it? New to javascript obviously.
    This the button now:
    Code:
    <input type="BUTTON" onclick="ajaxFunction()" value="ADJUST">

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    <input type="BUTTON" onclick="ajaxFunction();validateFunction();" value="ADJUST">
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    88
    Thanks
    12
    Thanked 0 Times in 0 Posts
    That was very good but the ajaxFunction gets called once the user clicks ok that the fields are empty
    the ajaxFunction simply calls this function for each field:

    Code:
    function isEmpty(elem, helperMsg){
    	if(elem.value.length == 0){
    		alert(helperMsg);
    		elem.focus();
    		return true;
    	}
    	return false;
    }
    so the server side code gets executed whether it is valid or not. I need the ajaxFunction to be called only if validation is TRUE.
    Last edited by beedie; 04-24-2008 at 08:30 AM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Then simply change the order of calling of these two functions Or call the second function at the end of the other's body.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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