/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Set onclick works in Opera, not IE/FF

I know the code isn’t perfect in terms of design, but it works as intended in Opera.

The issue arrises when you click one of the dates on the calendar, it should be highlighted and the date should appear in the box below, but in IE/FF I seem to be unable to set the onclick attribute for some reason, can anyone suggest a solution? Thanks.

[URL=”http://stuarts1.co.uk/calendar4.php”]The Calendar[/URL]
[URL=”http://stuarts1.co.uk/calendar4.js”]The JavaScript[/URL] (the code that doesn’t work is at lines 100-110)
[URL=”http://stuarts1.co.uk/calendar4.png”]What should happen[/URL]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayApr 09.2009 — Try changing the function to read:

<i>
</i>function setOnClick(ElementID, value) {
var MyElement = document.getElementById(ElementID);
MyElement.onclick = "function () { "+value+"}";
}
Copy linkTweet thisAlerts:
@Stu123authorApr 09.2009 — The change seemed to break it in Opera too, thanks for the suggestion though.
Copy linkTweet thisAlerts:
@TheBearMayApr 09.2009 — Okay try this:
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setOnClick(ElementID, val) {
var MyElement = document.getElementById(ElementID);
MyElement.onclick = function () { eval(val) };
}
</script>

</head>

<body>
<button onclick="alert('testing')" id="btn2Chg" >Push</button>
<input onchange="setOnClick('btn2Chg', this.value)" />

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@Stu123authorApr 09.2009 — Ok, that seems to work, thanks
×

Success!

Help @Stu123 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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