/    Sign up×
Community /Pin to ProfileBookmark

run JavaScript with out defining JavaScript

Cheers all,
I found this code online for preventing a form from being submitted twice via a double click. It works, but I’ve a question as to how it works since I’m not stating in code anywhere that it is JavaScript code.

Could it be the browsers are intelligent enough to know it is JS?

<input type=”submit” name=”submit” onclick=”this.disabled=true;this.value=’Submitting…’; this.form.submit();” />

I do not say anywhere, “Hey, this section is JavaScript”, so how does this work?

Thanks,

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mjdamatoJul 13.2007 — The code is simply implementing the javascrip inline. Form fields ahve built in triggers for running javascript: onsubmit, onclick, onmousedown, onmouseup, etc.
Copy linkTweet thisAlerts:
@Orc_ScorcherJul 13.2007 — Browsers simply use JavaScript as their default scripting language (most browsers don't support any other language anyway). In theory there is a HTTP header that lets you specify the default language for your page but in reality browsers don't support it.
Copy linkTweet thisAlerts:
@felgallJul 13.2007 — onclick is a JavaScript event handler and not an HTML attribute and so when you call the JavaScript event handler the browser knows that you want it to run JavaScript.
×

Success!

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