Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about onClick event handler

Status
Not open for further replies.

jain747

Technical User
Apr 22, 2003
17
US
I've just started learning w/ JS and cannot seem to figure out the error with the script below. Any help will be appreciated:

Code:
<HTML>
<HEAD>
<TITLE> An onClick= script </TITLE>
<SCRIPT LANGUAGE= “JavaScript”>
<!--
function alertUser() {
	alert("Ouch!")
}
//-->
</SCRIPT>
</HEAD>
<BODY>
Here is some body text.
<FORM>
  <INPUT TYPE="text" Name="entry">
  <INPUT TYPE="button" NAME="oneButton" VALUE="Press Me!">
onClick="alertUser()">
</FORM>
</BODY>
</HTML>
 
The only thing wrong that I can see are the "dodgy" quotes used when specifying the language:

Code:
<SCRIPT LANGUAGE= “JavaScript”>

They look like "smart quotes" which are usually generated by programs like Microsoft Word, and IMHO are definately not valid syntax in HTML or JavaScript to terminate strings. Try swapping them for regular quotes:

Code:
<SCRIPT LANGUAGE="JavaScript">

Hope this helps,
Dan
 

Oh yes - and the erroneous closing input tag before the onclick. Changing this:

Code:
 <INPUT TYPE="button" NAME="oneButton" VALUE="Press Me!">
onClick="alertUser()">

to this:

Code:
 <INPUT TYPE="button" NAME="oneButton" VALUE="Press Me!" onclick="alertUser()">

as well as the quotes issue, and you'll be sorted.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top