See many posts about this topic but nothing is working for me:
& lt; Script type = "text / javascript" & gt; Function openprompt () {$ .prompt ("Hello World!"); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; A href = "javascript: openprompt ()" & gt; Test Impropyt state survey & lt; / A & gt; & Lt; Div id = "result" & gt; & Lt; / Div & gt; & Lt; Div id = "wrapper" & gt; Some code ... & lt; Div id = "formWrapper" & gt; & Lt; Form action = "create.php" method = "post" onsubmit = "open openprompt ();" & Gt;
If I click on the link, the JS script runs fine and the prompt window opens, but when I click the submit button which is associated with the script, the script is not Moving I checked the database and found that the PHP script is working fine. Can someone please explain why the JS script is not running and there is a way to fix it. Thanks
That's because submissions will trigger a redirect for the action of the form. You have to disable it:
& lt; Form action = "create.php" method = "post" onsubmit = "openprompt (); return return;" & Gt;
A better way to do this, is to catch the event in JavaScript (for example, with jQuery):
Form Tag:
& lt; Form action = "create.php" method = "post" id = "my-form" & gt;
javascript:
$ (function () {$ ('# my-form'). ('Submit', function (e) {E.preventDefault (); // open the open openprompt (); return false;});});
Comments
Post a Comment