Skip to main content

Bug Tracker

Side navigation

#12128 closed bug (invalid)

Opened July 23, 2012 04:09PM UTC

Closed July 23, 2012 04:36PM UTC

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);

Attachments (0)
Change History (1)

Changed July 23, 2012 04:36PM UTC by dmethvin comment:1

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 }).