I want to clear the form form1
without clearing the textbox textbox1
. However the below does not work:
$('#form1').not("input[type=text]#textbox1").trigger('reset');
I could do .html('')
for each field except for textbox1
, but I do not want to do that since there will be more fields added to the form and therefore the manitaninability is not good.
Unfortunately the reset
event occurs on the form
and affects all form related elements within it. To achieve what you need you could select all your required form elements and set their values manually, eg:
$('#form1').find('input, select, textarea').not("#textbox1").val('');
The element selectors above should be generic enough to cater for additional fields being added to the form dynamically
You can first save the value on #textbox1
in a variable, then reset the form normally, and then assign the saved value to #textbox1
. This saves the hassle of selecting each and every input type and resetting it separately.
var value1 = $("input#textbox1").val();
$('#form1').trigger('reset');
$("input#textbox1").val( value1 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With