(Formatted Properly now) .... I have form as below:
<form style="padding:10px" id="myform" action="http://localhost/web/donedetails" method="post">
<div class="row half no-collapse-1">
<div class="6u">
<label><em>*</em> Your Name:</label>
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<label><em>*</em> Your Email:</label>
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<button type="submit" class="rate" id="submit">Submit</button>
</form>
and i am validating form as below:
$(document).ready(function(){
$('#name,#email').keyup(function(){
if($('#name').val().length !=0){
$("#name").css("border-color","#CCC");
}
if($('#email').val().length !=0){
$("#email").css("border-color","#CCC");
}
});
$('#submit').click(function(){
var name = $('#name').val();
var email = $('#email').val();
if( name.length == 0){
$('#name').css("border-color","red");
}
if( email.length == 0){
$('#email').css("border-color","red");
}
if(name.length != 0 && email.length != 0 ){
$("#myform").submit();
return true;
}
return false;
});
});
While submit, form is not going to donedetails
page. On clicking submit
, again same page is returned on which i am currently.
Note: donedetails
is a php page, i have written done details only as i have prohibited direct .php
access to files.
Please help to resolve it
Ok, instead of complicating the comment. Let I'll post an answer with the code change I suggested.
$(document).ready(function(){
$('#name,#email').keyup(function(){
if($('#name').val().length !=0){
$("#name").css("border-color","#CCC");
}
if($('#email').val().length !=0){
$("#email").css("border-color","#CCC");
}
});
$('#myform').submit(function(){
var name = $('#name').val();
var email = $('#email').val();
if(!name ){ // this is enough to check empty string, undefined etc.
$('#name').css("border-color","red");
}
if( !email ){
$('#email').css("border-color","red");
}
if(name && email){
return;
}
return false;
});
});
好吧,我认为您必须为操作脚本添加文件扩展名,因为它决定了将在服务器端选择哪个处理程序。
I Figured out the problem... and it just drove me crazy :) .... how my code can nt work.
The problem was that there were two form
tags.. and somehow i missed to close the first form
tag..
so the button was submitting only the first form
with blank action which is true :)
Finally, debugged the code and got the problem .... pheww.... just a small mistake and big impact it was
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.