Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html form reset not doing triggering select onchange

I am having a form where the fields need to change according to my select. But when I hit the reset the select resets back to default, but the onchange event on the select is not triggered. Is there anyway so that I can add that to my javascript?

I am resetting using a button with type="reset"

    $('#newHistoryPart select[name="roundType"]').on('change', function (data) 
    {
      $(".answerType").hide();
      selected = $(this).find("option:selected").val();
      roundTypeChange(selected); 
    });
like image 494
Mathias Avatar asked May 13 '15 12:05

Mathias


People also ask

Why is Onchange not working?

onchange is not fired when the value of an input is changed. It is only changed when the input's value is changed and then the input is blurred. What you'll need to do is capture the keypress event when fired in the given input. Then you'll test the value of the input against the value before it was keypressed.

How to reset form html?

You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.

What does reset() do?

reset() method restores a form element's default values. This method does the same thing as clicking the form's <input type="reset"> control. If a form control (such as a reset button) has a name or id of reset it will mask the form's reset method. It does not reset other attributes in the input, such as disabled .


1 Answers

From my comment above, use onreset event instead of onchange:

$('#yourform').on('reset', function(){
    // do something
});
like image 160
kosmos Avatar answered Sep 27 '22 20:09

kosmos