当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - When submitting form action doesn't follow after onsubmit code

问题描述:

I have a little form on my website but when I submit, the onsubmit executes but it never ends which is good because it is a loading icon. But it won't execute my action code so what is wrong in my code so that I would get my onsubmit active followed by the action command which the php file brings me to a succes page. (php file is ok). Thanks in advance!

<script

type="text/javascript">

function showHide() {

var div = document.getElementById("hidden_div");

if (div.style.display == 'none') {

div.style.display = '';

}

else {

div.style.display = 'none';

return false;

}

}

</script>

<form name="form2" method="POST" onsubmit="showHide(); return false;" action="\JocanasNLsuggest.php">

Ideeën voor nieuwe films, TV-series games of functies:<br><textarea class="input" name="comment" rows="5" cols="30" required></textarea><br><br>

<input type="submit" value="Voorstellen" name="submit">

</form>

<div id="hidden_div" style="display:none">

<div class="loader"></div>

</div>

网友答案:

Returning false from an event handler assigned with an intrinsic event attribute will prevent the default action.

In this case, the default action is submitting the form.

… and you are returning false from the function:

onsubmit="showHide(); return false;" 

… so just don't do that.

分享给朋友:
您可能感兴趣的文章:
随机阅读: