document.createElement

Discussion in 'Javascript' started by oeyvind toft, Sep 4, 2004.

  1. oeyvind toft

    oeyvind toft Guest

    oeyvind toft, Sep 4, 2004
    #1
    1. Advertising

  2. oeyvind toft wrote:

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


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 4, 2004
    #2
    1. Advertising

  3. oeyvind toft

    oeyvind toft Guest

    Of course, why didnt I think of that...


    Thanks Martin !!

    Oeyvind

    --
    http://home.online.no/~oeyvtoft/ToftWeb/



    "Martin Honnen" <> skrev i melding
    news:4139cdfd$0$28475$-online.net...
    >
    >
    > oeyvind toft wrote:
    >
    > > 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';
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    oeyvind toft, Sep 4, 2004
    #3
  4. oeyvind toft

    Ivo Guest

    > "Martin Honnen" skrev
    > >
    > > oeyvind toft wrote:
    > >
    > > > 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';


    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
    Ivo, Sep 5, 2004
    #4
  5. On Sun, 5 Sep 2004 23:32:43 +0200, Ivo <> wrote:

    [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.

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Sep 5, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weston C

    document.createElement('a') doesn't work?

    Weston C, Jan 9, 2004, in forum: Javascript
    Replies:
    4
    Views:
    102
    Michael Hill
    Jan 9, 2004
  2. Pieter Van Waeyenberge

    'wrap' inconsistency? createElement VS document.write

    Pieter Van Waeyenberge, Feb 9, 2004, in forum: Javascript
    Replies:
    3
    Views:
    175
    Pieter Van Waeyenberge
    Feb 11, 2004
  3. Dave

    Validate document.createElement

    Dave, Nov 5, 2004, in forum: Javascript
    Replies:
    2
    Views:
    158
    Martin Honnen
    Nov 5, 2004
  4. Andrew Poulos

    IE5 and document.createElement

    Andrew Poulos, Dec 6, 2004, in forum: Javascript
    Replies:
    2
    Views:
    103
    Andrew Poulos
    Dec 6, 2004
  5. James Black
    Replies:
    10
    Views:
    276
    Thomas 'PointedEars' Lahn
    May 25, 2006
Loading...

Share This Page