Submit button confirmation

I have a submit button:

<input class="create_button" name="commit" 
       onclick="return validate_activity();" 
       type="submit" value="Save">

I found that this button will always send a request to the server regardless of validate_activity () return true or false?

What is the problem?

UPDATE

Actually, I made a mistake in my validate_activity (), it makes me think that it returned false, but it is not.

+5
source share
6 answers

try to do the same without returning, for example. onclick="validate_activity();"and check if your function returns false if invalid

+10
source
<input type="button" name="commit"
value="Save"
onclick="validate_activity(myform)" />

Inside Javascript, when validating, execute form.submit()or return false.

, ! . , Javascript .

, , javascript ( , ),

<input type="button" name="commit"
value="Save"
onclick="validate_activity(myform);return false;" />

, . javascript - , , , , , .

+3

, onclick="return validate_activity();", ( false). - onclick="validate_activity();" false validata_activity, .

+2

If you do a form validation and then validate it on a button onclick, then the way you try it makes no sense to use it in an event <form></form> onsumbmitlike this.

<form action="someURL" method="post" onsubmit="return validate_activity();">

</form>
+2
source

Try it...

<form action="...." onsubmit="submitForm()" name="form">

<input type="submit" value="Save">

</form> 


function submitForm(){

    if(validationfails){

        return false;
    }
    else  {
        document.form.submit();
        return true;
    }
 }
+2
source

You must use the submitform event to validate.

<form action="..." method="..." onsubmit="return validate_activity()">
    <...>
    <input class="create_button" name="commit" type="submit" value="Save" />
    <...>
</form>
+1
source

All Articles