HTML and CSS Reference
In-Depth Information
example 5.3: Creating and assigning actions to buttons
<!DOCTYPE html>
<html>
<head>
<title>Example 5.3</title>
<script type="text/javascript">
/* Provide an array of destinations */
links = [ 'http://yahoo.com',
'http://google.com',
'http://bing.com' ];
/* simple function to link to a random URL */
function goToRandomURL() {
var x = Math.floor(links.length * (Math.random() % 1));
location = links[x];
return;
}
</script>
</head>
<body style="padding: 36px;">
<div style="text-align: center;">
<button id="btn1" onclick="location = this.value;"
value="about.html"> More Info </button>
<button id="btn2" onclick="goToRandomURL();"
value=""> Random Search Engine </button>
<button id="btn3" onclick="self.close();"
disabled="disabled" value="exit.html"> Go Away! </button>
</div>
...
</body>
</html>
Figure 5.3 shows how the buttons are rendered in a typical browser.
 
 
Search WWH ::




Custom Search