javascript - Override the form 'Reset' behavior when data is refreshed via ajax - Stack Overflow

I am relying on the "Reset" behavior of a form to cancel the edits, the problem i am facing i

I am relying on the "Reset" behavior of a form to cancel the edits, the problem i am facing is that once post the data is updated via ajax, the reset still reverts back to the data that was loaded with the page origionally.

So basically what I need to be able to do is "Reset" the "Reset" function. Make sense?

I am relying on the "Reset" behavior of a form to cancel the edits, the problem i am facing is that once post the data is updated via ajax, the reset still reverts back to the data that was loaded with the page origionally.

So basically what I need to be able to do is "Reset" the "Reset" function. Make sense?

Share Improve this question asked Oct 31, 2010 at 23:58 Rod JohnsonRod Johnson 2,4276 gold badges32 silver badges50 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Try this:

$("#yourForm").bind("reset", function() {

    // reset the form manually with the "newest" data

    return false;
});

In this case, you will have to store the new data (that you got from the Ajax callback). And then, when the user resets the form, you manually fill the form elements with that data.

There is also a native way.

form-elements have attributes to store the initial value.

To do this, the following would be interesting:

defaultValue(text-input,textarea)
defaultChecked(radio,checkbox)
defaultSelected(option)

So what to do to really set a new initial point for reset(): Walk the elements and assign the current attributes(value,checked,selected) to these default-attributes.

I don't think it's possible - Reset always reverts to the values provided in HTML code. I suppose the simplest way will be put received AJAX's data somewhere (ie hidden fields) and provide your custom Reset button which will load these (from hidden inputs or wherever you store them) data back into form.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745377693a4625075.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信