Want the html form to do nothing

I want the html form to do nothing after submitting it.

action="" 

not suitable because it causes a page reload.

Basically, I want the ajax function to be called whenever the button is pressed, or someone presses "enter" after entering the data. Yes, I can reset the form tag and add just call the function from the onclick event on the button, but I also want the "dial input" function not to become hacker.

+42
javascript html ajax submit forms
Aug 02 '10 at 4:19
source share
7 answers

Using return false; in javascript that you call from the submit button, you can stop the form from submitting.

Basically, you need the following HTML:

 <form onsubmit="myFunction(); return false;"> <input type="submit" value="Submit"> </form> 

Then supporting javascript:

 <script language="javascript"><!-- function myFunction() { //do stuff } //--></script> 

If you wish, you can also have certain conditions for the script to submit the form:

 <form onSubmit="return myFunction();"> <input type="submit" value="Submit"> </form> 

Connects to:

 <script language="JavaScript"><!-- function myFunction() { //do stuff if (condition) return true; return false; } //--></script> 
+60
Aug 02 2018-10-02T00:
source share

It also works:

 <form id='my_form' action="javascript:myFunction(); return false;"> 
+7
May 16 '11 at 14:56
source share

What about

 <form id="my_form" onsubmit="the_ajax_call_function(); return false;"> ...... </form> 
+2
Aug 2 '10 at 4:26
source share

You can use the following HTML

 <form onSubmit="myFunction(); return false;"> <input type="submit" value="Submit"> </form> 
+2
Aug 07 '10 at 7:35 a.m.
source share

As part of the onclick event return false button, which will stop the form from submitting.

t

 function doFormStuff() { // ajax function body here return false; } 

And just call this function by pressing the submit button. There are many different ways.

0
Aug 02 '10 at 4:26
source share

use jquery. Perhaps place a div around your elements from the form. Then use preventDefault () and then make your ajax calls

-one
Aug 02 2018-10-12T00:
source share
 <form action='javascript:functionWithAjax("search");'> <input class="keyword" id="keyword" name="keyword" placeholder="input your keywords" type="search"> <i class="iconfont icon-icon" onclick="functionWithAjax("search");"></i> </form> <script type="text/javascript"> function functionWithAjax(type) { // ajax action return false; } </script> 
-one
Apr 09 '17 at 1:55 on
source share



All Articles