3

I have the following Ajax.BeginForm inside my asp.net mvc razor view:-

    <div id="searchform">                           

    @using (Ajax.BeginForm("AdvanceSearchIndexByName","Home", 
    new AjaxOptions
    {
        HttpMethod = "get",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "progress2",
        UpdateTargetId = "SearchTable2"
    }))
    {
       }
<input class="btn btn-success" type="submit" value="Clear" id="clear" />

and i wrote the following javaScript:-

<script type="text/javascript">

    $("#clear").on('click', function () {
        alert('2');
        $('#searchform').clear();
});
        </script>

to reset the form values when clicking on the "clear" button, but currently the clear button will not have any effect.can anyone advice ? Thanks

john Gu
  • 7,691
  • 60
  • 207
  • 407
  • Maybe this is useful http://stackoverflow.com/questions/6653556/jquery-javascript-function-to-clear-all-the-fields-of-a-form – mitomed Jul 11 '14 at 10:37

1 Answers1

3

You can do this without any JavaScript, just add a reset type button

 @using (Ajax.BeginForm("AdvanceSearchIndexByName","Home", 
    new AjaxOptions
    {
        HttpMethod = "get",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "progress2",
        UpdateTargetId = "SearchTable2"
    }))
 {
        <input type="reset" value="reset"/>

 }
Liam
  • 25,247
  • 27
  • 110
  • 174
  • what an answer,, this is exactly what i was searching for,, strange that i have been using Ajax.BeginForm on many projects, but never know about its reset capabilities ... – john Gu Jul 11 '14 at 10:47
  • 2
    That's a HTML 4.0 capability! This has been around for a very long time. People just forget about it. – Liam Jul 11 '14 at 11:00