/    Sign up×
Community /Pin to ProfileBookmark

onClick w/ getElementById Problem

Hi, just started messing around with another webpage tonight and had a specific part working pretty well until I realized what worked with Mozilla wasn’t working at all on IE8

Could someone tell me how to get around this or what to change. I’m essentially just using an onClick to change the attribute of a Div layer from Display:None to Display:Block

[CODE]<Script type = ” Text/Javascript “>
function HideBox(DivId)
{ document.getElementById(DivId).style.display=’none’}
function ShowBox(DivId)
{ document.getElementById(DivId).style.display=’block’}

</Script>

<a href=”” onClick=”ShowBox(‘CTMain530’); return false;”>
<Img Src=”http://homepages.nyu.edu/~cjp307/padres” width=119 height=119 border=0></a>[/CODE]

Basically CTMain530 is a hidden div that I want to change to block, but it doesnt work in IE8 only Mozilla. What can I do?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 30.2009 — Is 'CTMain530' unique to the document?
Copy linkTweet thisAlerts:
@SyCSauthorMay 30.2009 — Is 'CTMain530' unique to the document?[/QUOTE]

Yes, its a div layer inside the document, the only div w/ that name
Copy linkTweet thisAlerts:
@FangMay 30.2009 — Can we see the full document?
Copy linkTweet thisAlerts:
@astupidnameMay 30.2009 — Use proper script tags, and no spaces in the type attribute declaration:
&lt;script type="text/javascript"&gt;

&lt;/script&gt;
Copy linkTweet thisAlerts:
@SyCSauthorMay 30.2009 — Oh wow that actually worked. So why is Mozilla not as picky about spaces/caps as IE?

Thank you
Copy linkTweet thisAlerts:
@astupidnameMay 30.2009 — I don't know, I guess IE get's some things right that Mozilla doesn't (poorly formed commands should not be executed, IMO)
Copy linkTweet thisAlerts:
@SyCSauthorMay 30.2009 — I honestly wasn't attempting to poorly frame them. I initially write it correctly, but then I tend to get really OCD with my coding so I space everything out so it all alligns with each other. Something I did through out compsci in college. Just got a surprise when IE got picky about it
Copy linkTweet thisAlerts:
@FangMay 31.2009 — Both browsers implement it incorrectly:

JavaScript is case sensitive - both get it wrong

Leading/trailing whitespace in attribute values should be ignored - IE gets it wrong

Use the validator: http://validator.w3.org/
×

Success!

Help @SyCS 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.17,
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,
)...