2013-08-18 10:31



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">


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"> 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doulong6761 doulong6761 8年前

    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
        function validateForm(){
                //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!

    点赞 评论 复制链接分享
  • douiwn6941 douiwn6941 8年前


    return false; 

    in the end of your delete_exe(); function. That will cancel submitting.

    点赞 评论 复制链接分享