Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-28-2003, 02:09 AM   PM User | #1
Vlaad
New Coder

 
Join Date: Mar 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Vlaad is an unknown quantity at this point
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
Vlaad is offline   Reply With Quote
Old 05-28-2003, 02:30 AM   PM User | #2
Vlaad
New Coder

 
Join Date: Mar 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Vlaad is an unknown quantity at this point
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
Vlaad is offline   Reply With Quote
Old 05-28-2003, 03:11 AM   PM User | #3
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
x.addEventListener("click", function(event) { blablabla }, false);

Is the DOM2 way of adding events to elements.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 05-28-2003, 08:41 AM   PM User | #4
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:12 PM.


Advertisement
Log in to turn off these ads.