Reset, except for one input enclosed in a DIV

I use this for the reset form when the visitor refreshes the page:

$(document).ready(function () { resetForms(); }); function resetForms() { document.getElementById('configurator-form').reset(); } 

Inputs are radio, selection, text. There is one input inside (div class = "binding") that I need to exclude from reset. How can i do this?

Can i use:

 .not('.snap input') 

Where? I think for this I will need to focus on the inputs, and not on the whole form? Fields have default values, so I don't think I want to use 'removeAttr', although I could be wrong?

EDIT

I know this seems like a different question, but I can't get the accepted answer to the job. He suggested that the value of the form is accepted, then the form is reset, then the value is returned to the form. I tried with this:

 $(window).load(function() { var snap = $(".snap input").val(); resetForms(); $(".snap input").val(snap); }); function resetForms() { document.getElementById('configurator-form').reset(); } 

... But he did not restore the value of the ".snap input" field. It is worth noting that the binding field has a random name and identifier, so I cannot use getElementById, for example. Thank you for your patience, as you can probably say I'm new to jQuery.

EDIT 2

Well, resetForms throws an "undefined" error. This version works just fine:

 $(document).ready(function(){ var snap = $(".snap").html(); $('#configurator-form')[0].reset(); $(".snap").html(snap); }); 
+1
source share
1 answer

You must work.

The only mistake you have is the selector,

Your JS should look like this: (no space in the selector)

 function resetForms() { var value = $("input.snap").val(); document.getElementById('configurator-form').reset(); $("input.snap").val(value); } 

working violin

0
source

Source: https://habr.com/ru/post/1208229/


All Articles