document.createElement

O

oeyvind toft

How do I create a checkbox element ? Or any other input type ?
document.createElement('checkbox') doesnt seem to work.

Oeyvind
 
M

Martin Honnen

oeyvind said:
How do I create a checkbox element ? Or any other input type ?
document.createElement('checkbox') doesnt seem to work.

var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.name = 'checkboxName';
checkbox.defaultChecked = true/false
checkbox.value = 'Kibology';
 
I

Ivo

"Martin Honnen" skrev
Some browsers have a problem assiging names to dynamically created input
elements in this way. You should define the name like so:

var checkbox = document.createElement('<input name="chName">');

--Iv
 
M

Michael Winter

[Modifying attributes after a createElement call]
Some browsers have a problem assiging names to dynamically created input
elements in this way. You should define the name like so:

var checkbox = document.createElement('<input name="chName">');

Whilst Microsoft may support that syntax, it is *not* correct. The
argument is the element name only.

I can't test with Mozilla at the moment, but Opera returns undefined[1]
with such a call, so the approach cannot be recommended at all.

Mike


[1] I'm surprised it didn't throw an exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top