javascript - How to Reset Newly Added Form Inputs -
edits:
1. removed code unnecessary...
2. clarified desired solution , added reset button html.
i've seen various methods used reset form add content blank div (id = "unitpulled") via ajax so, methods similar following not work:
document.forms[0].reset();
my goal reset entire form when user hits reset button.
how go tackling issue? dom have reloaded?
html button:
<button id="reset" name="reset" class="btn btn-default" type="reset">clear</button>
javascript:
/* below auto-updating of initial , number */ var oxmlhttp function showunits(str) // change function name { var url = "ajax.cfm?&lic_plate=" + str // change url oxmlhttp = gethttpobject(statechanged) oxmlhttp.open("get", url, true) oxmlhttp.send(null) } // below new elements added: function statechanged() { if (oxmlhttp.readystate == 4 || oxmlhttp.readystate == "complete") { document.getelementbyid("unitpulled").innerhtml = oxmlhttp.responsetext; // change id document.getelementbyid("lic_plate").focus(); } }
thanks!
add line in function statechanged()
function statechanged() { if (oxmlhttp.readystate == 4 || oxmlhttp.readystate == "complete") { document.getelementbyid("unitpulled").innerhtml = oxmlhttp.responsetext; // change id document.getelementbyid("myform").reset(); document.getelementbyid("lic_plate").focus(); } }
please put form id instead of myform. let me know if not working form value reset after ajax call.
Comments
Post a Comment