Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable submit action

Hi i have have this form that i do no want to perform an action when the submit button is clicked. All i want to do is perform the 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>
like image 784
Fadamie Avatar asked Apr 30 '12 05:04

Fadamie


1 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. for example:

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

Final code using jQuery:

<script>
    $(function() { 
        $("#search-form").submit(function() { 
            $("div").load("file.xml");
            return false;
        });
    });
</script>
like image 85
Alon Gubkin Avatar answered Oct 04 '22 19:10

Alon Gubkin