the trouble with arguments

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

the trouble with arguments

 
0
  #1
Jan 31st, 2008
I am a Javascript newb, and I am haveing some trouble with my arguments.

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

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.

  1. while($row=mysql_fetch_array($query))
  2. {
  3. echo '
  4. <td class="bar" onmouseover=Javascript:openMenu("' . $row['category'] . '")
  5. onmouseout=Javascript:closeMenu("' . $row['category'] . '")>
  6. <a href="category.php?cat=' . $row['category'] . '" class="top_menu"><div>' . $row['category'] . '</div></a><div>';
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: the trouble with arguments

 
0
  #2
Jan 31st, 2008
Originally Posted by hooray View Post
I am a Javascript newb, and I am haveing some trouble with my arguments.
  1. while($row=mysql_fetch_array($query))
  2. {
  3. echo '
  4. <td class="bar" onmouseover=Javascript:openMenu("' . $row['category'] . '")
  5. onmouseout=Javascript:closeMenu("' . $row['category'] . '")>
  6. <a href="category.php?cat=' . $row['category'] . '" class="top_menu"><div>' . $row['category'] . '</div></a><div>';
Based on the W3C standards you must encapsulate attribute values in quotes ie, name="hello" is right, name=hello is wrong.
So your echo is breaking the script.
  1. echo
  2. "<td class='bar' onmouseover='openMenu(\"".$row['category']."\");'
  3. onmouseout=''closeMenu(\"".$row['category']."\");' >
  4. <a href='category.php?cat=".$row['category']."' class='top_menu'><div>".$row['category']."</div></a><div>\n";
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC