dragon19720808
dragon19720808
2013-08-18 10:31

用图像按钮调用js函数用php而不提交

已采纳

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

2条回答

  • 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
                    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!

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

    Use

    return false; 
    

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

    点赞 评论 复制链接分享

为你推荐