Im coding php and i want to use image-button to call function.
$del= "<input type='image' src='delete.png' name='delete_cat' value='{$cat_name}' onclick='delete_exe(this.form,this.name,this.value)' >";
This button is into a submit form
<form method="post" action="caffe_menu_category_post.php">
/form>
My problem is that when js function(delete_exe()
) call and execute, then have auto-submit. I don't want that. Is there any solution or alternative code? Can i set submit off for my button?
Thanks in advance.
ps in my code i submit form with submit input
input type = "submit" value = "Submit Your Entries">
Ok. i find the solution. I change my post form
form name="myForm" method="post" action="caffe_menu_category_post.php" onsubmit="return validateForm()">
And use javascripts
var val=true;
function delete_exe(sel,kind,name){
//Set val false to stop submit
val=false;
}
function validateForm(){
if(!val){
//Stop submit
return false;
}
}
So the auto-submit stop. On the oher hand when click submit button i call js function to set val=true;
i don't know if these is the best solution, but it's work for me!
Use
return false;
in the end of your delete_exe();
function. That will cancel submitting.