Page 1 of 1

javascript help

Posted: Sat Mar 25, 2006 2:18 pm
by elecktricity
im really not sure why this code dosnt work, im somewhat new at javascript so yea any help or links are greatly appreciated, its suppose to be a dyanmic imagemap background that also sets a hidden variable to post data, its suppose to alert you of what 'num' is but it wont work with variables just strings, so im not sure how to get the alerts to work either:

Code: Select all

<script language="Javascript">
document.write('<html>');
document.write('<head>');
document.write('<title>Star Rating</title>');
document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
document.write('</head>');
document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
alert (num);
	function star(num) {
	int num;
		if (num=='') {
		num = 1;
		}
			int
		document.write('<img src="star' + num + '.gif" width="80" height="15" border="0" alt="" usemap="#stars_Map">');
		decument.write('<input type="hidden" name="rating" value="' + num + '">');
	}
alert (num);
document.write('<map name="stars_Map">');
document.write('<area shape="rect" onMouseover="star(1)" alt="Rate 5" coords="64,0,79,15" href="5.html">');
document.write('<area shape="rect" onMouseover="star(2)" alt="Rate 4" coords="48,0,63,15" href="4.html">');
document.write('<area shape="rect" onMouseover="star(3)" alt="Rate 3" coords="32,0,47,14" href="3.html">');
document.write('<area shape="rect" onMouseover="star(4)" alt="Rate 2" coords="16,0,31,14" href="2.html">');
document.write('<area shape="rect" onMouseover="star(5)" alt="Rate 1" coords="0,0,15,14" href="1.html">');
document.write('</map>');
document.write('</body>');
document.write('</html>');
</script>
its just displaying a blank page.

Posted: Sat Mar 25, 2006 2:28 pm
by Christopher
Seems like you need to display the image with the name stars_Map somewhere. The image map won't do anything without an associated image.

Posted: Sat Mar 25, 2006 2:30 pm
by elecktricity
image map was made in imageready so it should work right, I think I tested it without js and it worked, I just need a few things dyamic, and I think it does have what your talking about when defining the map:
<map name="stars_Map">

Posted: Sat Mar 25, 2006 5:42 pm
by elecktricity
this is the updated version that works perfect, but only works once then dosnt work

Code: Select all

<html>
<head>
<title>Javascript Tests</title>
</head>
<body>
<script type="text/javascript">
function star(number) {
document.write('<img src="star' + number + '.gif" width="80" height="15" border="0" alt="" usemap="#stars_Map">');
document.write('<input type="hidden" name="rating" value="' + number + '">');
}
star(3);
</script>
<input type="hidden" name="rating" value="">
<map name="stars_Map">
<area shape="rect" onMouseover="star(5)" alt="Rate 5" coords="64,0,79,15" href="5.html">
<area shape="rect" onMouseover="star(4)" alt="Rate 4" coords="48,0,63,15" href="4.html">
<area shape="rect" onMouseover="star(3)" alt="Rate 3" coords="32,0,47,14" href="3.html">
<area shape="rect" onMouseover="star(2)" alt="Rate 2" coords="16,0,31,14" href="2.html">
<area shape="rect" onMouseover="star(1)" alt="Rate 1" coords="0,0,15,14" href="1.html">
</map>
</body>

</html>