Umm...I'm a bit new to Javascript, this is my first script in it o.0
<HTML>
<HEAD>
<TITLE>dot Syntax</TITLE>
<SCRIPT Language="JavaScript">
<!--
function changeLabel(){
if (document.buttonDemo.HelloWorldButton.value==" Hello "){
document.buttonDemo.HelloWorldButton.value=" World"
}
else{
document.buttonDemo.HelloWorldButton.value=" Hello "
}
}
//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="Red">
<P>
<FORM name="button">
<INPUT type="Button" value=" Hello " name="HelloWorldButton"
onClick="changeLabel()">
</FORM>
</BODY>
</HTML>
All that I know is by trying to write scripts, but beforehand, I picked up the basics from these two links:
http://www.w3schools.com/dhtml/default.asp
http://www.w3schools.com/htmldom/default.asp
Work through those and you\'ll be an expert!
Excellent MountainDew!
pokemaster23:
You could write this much more simply through use of DHTML:
<INPUT type=\"Button\" value=\"Hello\" onclick=\"this.value=\'World\'\" >
When clicked, it changes to \'World\'. You can also specify it to when it is hovered over, hovered out etc. For example:
<INPUT type=\"Button\" value=\"Hello\" onclick=\"this.value=\'World\'\" onmouseover=\"this.value=\'mouse\'\" >
When the mouse hovers over, it returns \'mouse\'
@MountainDew:
The Javascript comment looks different (/*) to an HTML one (<!--)
They use this so that a browserwhich does not support Javascript will not display the Javascript as plain text. A browser which does support Javascript will see the <script type=\"text/javascript\"> and ignore the HTML comment.
Whoa, guys, calm down.
type attribute missing - error 1.
semi-colons missing - not an error, but good fashion.
Elements in uppercase - Won\'t validate.
onClick There is no such attribute; it\'s onclick
What I don\'t understand is, how can post such a pointless code in the snippets section? There\'s no use to it.