Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12128 closed bug (invalid)

dynamic html checkbox value bug (IE only)

Reported by: adrienfrediani Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

When creating a dynamic input checkbox, using $.(html, json) when we pass value as a parameter this doesn't seems to be set correctly. (a call to $.val() always return 'on').

ex: var $elt = $('<input />', {value: 'foo'}).appendTo($container);

on IE: $elt.val() returns 'on'

on other browsers: $elt.val() returns 'foo'

This seems to be appears only for input type checkbox.

Only reproducible on IE 7, 8 and 9.

On chrome/FF everything works fine (a call to $.val() returns expected value)

Please see http://jsfiddle.net/frediana/Ap3DY/8/

As a workaround you can manually cal val after, this solve the problem but looks like a hack to me.

ex: var $elt = $('<input />').appendTo($container); $elt.val('foo);

Change History (1)

comment:1 Changed 7 years ago by dmethvin

Resolution: invalid
Status: newclosed

You shouldn't change the type after you've set the value.

http://jsfiddle.net/Ap3DY/9/

I also strongly advise against $(html, { stuff }) because it probably doesn't do what you think it does. You should be using .prop() to set properties and you can't do that with $(html, { stuff }).

Note: See TracTickets for help on using tickets.