javascript help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

javascript help

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post 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">
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post 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>
Post Reply