How to disable the submit action

Hi, I have such a form that I do not want to perform an action when I click the submit button. All I want to do is execute a function that loads data into a div. Any ideas?

<form method="POST" action="" id="search-form"> <input type="text" name="keywords" /> <input type="submit" value="Search" id="sButton" onclick="loadXMLDoc('file.xml')" /> </form> 
+7
source share
2 answers
 onclick="loadXMLDoc('file.xml'); return false;" 

or even better:

 <script> window.onload = function() { document.getElementById("search-form").onsubmit = function() { loadXMLDoc('file.xml'); return false; }; }; </script> 

To implement loadXMLDoc, you can use the ajax module in jQuery. eg:

 function loadXMLDoc() { $("div").load("file.xml"); } 

Final code using jQuery:

 <script> $(function() { $("#search-form").submit(function() { $("div").load("file.xml"); return false; }); }); </script> 
+8
source

I think you need ajax function to load data using div without reloading the page

Change input type submit to button

 <input type="button" value="Search" id="sButton" onclick="AjaxSend()" /> 

Ajax CAll:

 <script type="text/javascript"> function AjaxSend(){ $.get('file.xml', function(data) { $('div').html(data); }); } </script> 
+2
source

All Articles