954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

the trouble with arguments

I am a Javascript newb, and I am haveing some trouble with my arguments.

function openMenu(tableName)	{
document.getElementById(tableName).style.visibility="visible";
}


This is the code i have, and it is working perfectly on the different menus at the top of my screen. The problem i have is with my table IDs, i get the ids from a database using php, and one of them has a space in the centre, so that one doesnt work. This is my php if anything can be changed in either language i would be grateful for any help.

while($row=mysql_fetch_array($query))
	{
	echo '
	<td class="bar" onmouseover=Javascript:openMenu("' . $row['category'] . '")
	onmouseout=Javascript:closeMenu("' . $row['category'] . '")>
	<a href="category.php?cat=' . $row['category'] . '" class="top_menu"><div>' . $row['category'] . '</div></a><div>';
hooray
Junior Poster in Training
62 posts since Jan 2008
Reputation Points: 11
Solved Threads: 6
 

I am a Javascript newb, and I am haveing some trouble with my arguments.

while($row=mysql_fetch_array($query))
	{
	echo '
	<td class="bar" onmouseover=Javascript:openMenu("' . $row['category'] . '")
	onmouseout=Javascript:closeMenu("' . $row['category'] . '")>
	<a href="category.php?cat=' . $row['category'] . '" class="top_menu"><div>' . $row['category'] . '</div></a><div>';


Based on the W3C standards youmust encapsulate attribute values in quotes ie, name="hello" is right, name=hello is wrong.
So your echo is breaking the script.

echo 
"<td class='bar' onmouseover='openMenu(\"".$row['category']."\");' 
                 onmouseout=''closeMenu(\"".$row['category']."\");' >
   <a href='category.php?cat=".$row['category']."' class='top_menu'><div>".$row['category']."</div></a><div>\n";
ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You