/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] FF/chrome ok, IE doesn’t work

Hey,

I’ve finished this code, and don’t know why but IE doesn’t execute it. Could it be because IE runs JScript, not Javascript?

Basically two pictures “1” and “2” are in the <body>. Clicking on one of these runs the function pairs1() below, making two other pictures “3.jpg” and “4.jpg” appear. You should be able to click on one of “3” or “4”, and again, 2 more pictures “5” and “6” should appear. Unfortunately these last two don’t appear!

I think the problem could be that IE doesn’t recognise these lines:

[CODE]picthree.setAttribute(“onclick”,”pairs2(‘3’)”);
picfour.setAttribute(“onclick”,”pairs2(‘4’)”);
[/CODE]

FYI pairs2() is almost identical to the code below, and creates the two images “5” and “6” – but of course pairs2() isn’t called in IE when “3” or “4” are clicked on.

Any ideas why?

[CODE]
function pairs1(pic) {
var picthree = document.createElement(“img”);
var picfour = document.createElement(“img”);
picthree.setAttribute(“src”,”3.jpg”);
picfour.setAttribute(“src”,”4.jpg”);
picthree.setAttribute(“alt”,”3″);
picfour.setAttribute(“alt”,”4″);
picthree.setAttribute(“onclick”,”question6b(‘3’)”);
picfour.setAttribute(“onclick”,”question6b(‘4’)”);
var docBody = document.getElementsByTagName(“body”)[0];
docBody.appendChild(picthree);
docBody.appendChild (picfour);
if (pic == ‘1’) {
answer = “Correct”
}
else answer = “Incorrect”
}
}

[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 20.2009 — Works in all browsers:picthree.onclick=function() {pairs2('3');};
Copy linkTweet thisAlerts:
@javascriptloverauthorJan 20.2009 — GENIUS!!!

A thousand thanks sir.
×

Success!

Help @javascriptlover 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...