Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating Button elements - form-submit issue

    Greetings, salutations.

    When creating an input element, one must declare the type, which then becomes immutable.
    Code:
    el = document.createElement('input');
    el.type = 'text';
    Fine. No problem. However! When creating a button element, one may not declare the type, as it is created as immutable.
    Code:
    .el = document.createElement('button');
    el.type = "button";
    My issue is that I don't want this button to submit the form, which it does because the default button type is "submit." Quote the spec:
    Code:
    <!ELEMENT BUTTON - -
         (%flow;)* -(A|%formctrl;|FORM|FIELDSET)
         -- push button -->
    <!ATTLIST BUTTON
    ...
      type        (button|submit|reset) submit -- for use as form button --
    ...>
    The oddest part is that after the button is created, alert(el.type) yields undefined in the alert.

    Does anyone know more about using the button element with DOM?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is kind of weird..

    To be quite honest with you, I've used this in the past, but apparently it's incorrect:
    Code:
    el = document.createElement("<button onClick='alert()'>");
    el.appendChild(document.createTextNode("push me"));
    And that should create a regular button, not a <input type="submit">

    I've never had the opportunity to test this out in NS or any other browser other than IE, so that may be IE only..

    Hope that helps,
    Sadiq.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try: el.setAttribute("type", "button")
    hmm... ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •