0

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"> 
Tomasz Banasiak
  • 1,540
  • 2
  • 13
  • 19
Mixalis
  • 309
  • 1
  • 3
  • 12

2 Answers2

0

Use

return false; 

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

Tomasz Banasiak
  • 1,540
  • 2
  • 13
  • 19
  • Unfortunately that is not my solution. I have the same auto-submit. Even if i don't call the function and have '$del= "' the click make submit. – Mixalis Aug 18 '13 at 10:44
  • So if your image should not submit this form, maybe change it to "standard" `` tag with `onClick` action binded? – Tomasz Banasiak Aug 18 '13 at 10:51
  • It is more complicate than i want. I have multiple image-buttons so i want when click one of them, call javascript with 3 elements – Mixalis Aug 18 '13 at 11:01
0

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!

Mixalis
  • 309
  • 1
  • 3
  • 12