/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] getting javascript to validate?

I read somewhere a while ago about a way to get javascript handlers like onClick and others to validate with the w3c.

it said something about using javascript to relate that handler to a style id then give your tag that id and the javascript would work like normal and your html will still be valid.

anyone know how to do that? or know of a page that describes it? I don’t know where that page is, I found it on accident and of course if I try to search for validating javascript I get endless pages of form tutorials. I’m trying to make it a personal goal to make a completely standards compliant site. never done it before so hey, why not?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 03.2006 — I don't understand. Except maybe that you should use lowecase so that [B]on[COLOR=Red]c[/COLOR]lick[/B] would be a valid W3 event, nomatter which tag bears it, nomatter the doctype
Copy linkTweet thisAlerts:
@bubsauthorNov 03.2006 — when I validate my html I get this " Error Line 472 column 57: there is no attribute "onClick".

<img id="link1" class="weight" src="weight2.gif" onClick="toggleBox('peek',0);" />

it is in lowercase

I read somewhere that you can take the "onClick" out of the line and leave it in the head while associating it with an id. so this is the only thing thats in the body of the document <img id="link1" class="weight" src="weight2.gif" /> but it still calls the javascript.

but I don't know much about javascript so I don't know how to go about doing this.
Copy linkTweet thisAlerts:
@KorNov 03.2006 — Well yes, you may attach the event onload, if u want to
<i>
</i>&lt;script type="text/javascript"&gt;
onload=function(){
document.getElementById('link1').onclick=function(){toggleBox('peek',0)}
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@bubsauthorNov 03.2006 — this isn't the exact article I read but it explains what I was trying to say... separate behavior and structure

http://www.digital-web.com/articles/separating_behavior_and_structure_2/
Copy linkTweet thisAlerts:
@bubsauthorNov 03.2006 — yea stuff like that... and then add all that stuff in an external .js so all thats in your html is html!!! Personally I like the way it looks rather than put an onWhatever on lots of links. cool

but thats just me... thanks for the help! really appreciated.
Copy linkTweet thisAlerts:
@KorNov 03.2006 — if you set wisely the id's, by indexing them (link0, link1, link2...), the code is short enough, something like
<i>
</i>onload=function(){
var i=0, obj
while(obj=document.getElementById('link'+(i++))){
obj.ind=i-1;
obj.onclick=function(){toggleBox('peek',this.ind)}
}
}

this is equivalent with the blue
<i>
</i>&lt;img id="link0" class="weight" src="weight2.gif" [COLOR=Blue]onclick="toggleBox('peek',0);"[/COLOR] /&gt;
&lt;img id="link1" class="weight" src="weight2.gif" [COLOR=Blue]onclick="toggleBox('peek',1);"[/COLOR] /&gt;
&lt;img id="link2" class="weight" src="weight2.gif" [COLOR=Blue]onclick="toggleBox('peek',2);"[/COLOR] /&gt;
... and so on
Copy linkTweet thisAlerts:
@bubsauthorNov 03.2006 — YOUR AWESOME!

thanks for that bit of script that will help me out a ton!

very cool
×

Success!

Help @bubs 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.9,
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,
)...