javascript - Form reset and programmatically set values -


i trying reset form using:

myform.reset(); 

i tried set values way:

//solved setting $('#mytextcontrol').attr('defaultvalue', 'my initial value'); //thanks robg $('#mytextcontrol').val('my value'); $('#mytextcontrol').attr('value', 'my value');  //solved setting $('#mytextcontrol').attr('defaultchecked', false or true); $('#mycheckboxcontrol')attr('checked', 'checked');       //finally works radios too, shown here -> http://jsfiddle.net/4vakp/2/ $('#myradiocontrol')attr('checked', 'checked'); 

the way update value important, can see here -> http://jsfiddle.net/4vakp/3/ updating value using attr fix value default: wrong

radio2.attr('checked', true); text2.attr('value', 'my text2'); 

this not set value default (as expected): correct

radio.prop('checked', true); text.val('my text'); 

this works fine when values set user, don't work if values set programmatically.

if set value programmatically first, through ui , reset it, comes programmatically set on.

i suspect there should way set value programmatically without changing default.

any thoughts?

thanks in advance,

eric

resetting form sets controls default value, either specified value attribute or set defaultvalue property. changes user not change either of these—except in (older?) ie, getattribute buggy.

to "reset" form other set of values without modifying ether value attribute or defaultvalue property, value property of controls must programmatically set.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -