Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all forms on page load

I want to clear all forms on page load. I tried to use this function on domready, but it doesn't help. I'm new to JavaScript. Is there anything wrong with this function?

   $(':input', form)
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');
like image 502
Tural Ali Avatar asked Nov 17 '11 23:11

Tural Ali


2 Answers

You can try using the plain javascript reset method on a form

$('form').each(function() { this.reset() });

This should reset each form to its default state.

To re-enable all checkboxes, you can try:

$(':checkbox').prop('disabled', false);
like image 172
Doug Owings Avatar answered Sep 21 '22 01:09

Doug Owings


maybe this is what your asking? not sure why you would need it. the fields should be blank on page load anyways. you should change the values php side.

$('input[type=text]').val('');
$('input[type=radio]').checked=false;
$('input[type=checkbox]').checked=false;

or maybe even

$("input:not(':button, :submit, :reset, :hidden')").val('').checked=false;
like image 23
Johnny Craig Avatar answered Sep 18 '22 01:09

Johnny Craig