My code is in the
view
<?php echo CHtml::SubmitButton('Submit',array('onclick'=>'return validation();'));?>
and my script function is
function validation(){
jQuery("#firstname_result").hide();
jQuery("#lastname_result").hide();
jQuery("#email_result").hide();
var firstname =jQuery("#first_name").val();
var lastname = jQuery("#last_name").val();
var email = jQuery("#email").val();
success=true;
if(firstname==''){
success=false;
jQuery('#firstname_result').html('First Name cannot be blank.').show();
}
if(lastname==''){
success=false;
jQuery('#lastname_result').html('Last Name cannot be blank.').show();
}
if(email==''){
success=false;
jQuery('#email_result').html('Email cannot be blank.').show();
}
if(!success)
return;
}
after clicking submit button, shows error and flashed out to other page where submit is targeted..can any one show me the way how I can able to overcome from this?
Try returning the value of the success variable. it should do the trick.
should be
this will stop the form from sumitting.