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 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setAttribute Hassles (again!)

    Howdy,

    I checked out the W3C site, and looked at the DOM2 specification (particularly: org/w3c/dom/html2/HTMLInputElement.java) because my x.setAttribute('onClick','myFunction') doesn't work for me.

    I was hoping there'd be an x.onClick='myFunction' method, but there's not.

    Please help, and thanks in advance.
    - Vlaad

  • #2
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy following up from that...

    I thought I'd be clever and try translating it back to partial rubbish-code and use the x.innerHTML='...' method, but I get "unspecified" errors in both IE and Moz.

    x = document.createElement('input');
    x.innerHTML="class='text' type='text' name='MarginCalculator"+rowCounter+"' id='MarginCalculator"+rowCounter+"' readonly onClick='javascript: myFunction'";

    myFunction is blank, and all the quotes are in the correct positions... the code seems sound. I've had it running before by writing out the entire input tag in pure HTML using innerHTML= within a td. However, I do NOT want to have to do such an ugly thing.

    Please... this really needs to be fixed ASAP, or I'm gunna get reamed!
    - Vlaad

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    x.addEventListener("click", function(event) { blablabla }, false);

    Is the DOM2 way of adding events to elements.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    If you don't want to do the JKD way (and thus ignore ie) you can do
    Code:
    element.onclick=function(e,...){/*function body*/}
    Note the case of the "onclick", and the fact you give it a function instead of a string.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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