/    Sign up×
Community /Pin to ProfileBookmark

onClick problem in IE..how to get around it.

Hi all,

I know this issue has been addressed (cannot use ‘setAttribute(‘onClick’, ‘somefunc’) in IE). I also have found other forums that talked about just setting the ‘onclick’ function for the element directly (element.onclick = function() {somefunc();};

What I need to do is to set the onclick function dynamically via javascript. Nothing I have done in IE has worked. I.e.

function createCell(record_id)
{
var cell = document.createElement(“td”);
…..
cell.onclick= “function() { somefunc(‘ + record_id + ‘);};”
……
return cell;
}

the way I am trying to set the onclick is causing errors. I tried using ‘eval’ but also received errors.

Any ideas would be greatly appreciated.

thanks,
Bill

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@svidgenJun 20.2012 — Define the onclick function normally (not string-encapsulated), as though it's any other function:

[code=php]var createCell = function (record_id) {
var cell = document.createElement('td');
cell.onclick = function() { somefunc(record_id); }
return cell;
}[/code]
Copy linkTweet thisAlerts:
@paraglidersdauthorJun 20.2012 — That worked. I cant believe I didnt try it that way. Thank you very much for your input.

Bill
×

Success!

Help @paraglidersd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...