Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-05-2009, 10:25 PM   PM User | #1
php_guest
New Coder

 
Join Date: Jun 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
php_guest is an unknown quantity at this point
$('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

Last edited by php_guest; 06-05-2009 at 10:32 PM.. Reason: forgot to mention I use jquery
php_guest is offline   Reply With Quote
Old 06-06-2009, 09:15 AM   PM User | #2
php_guest
New Coder

 
Join Date: Jun 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
php_guest is an unknown quantity at this point
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;
}
php_guest is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:07 AM.


Advertisement
Log in to turn off these ads.