943,699 Members | Top Members by Rank

Ad:
Jan 31st, 2008
0

the trouble with arguments

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

javascript Syntax (Toggle Plain Text)
  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.

php Syntax (Toggle Plain Text)
  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>';
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Jan 31st, 2008
0

Re: the trouble with arguments

Click to Expand / Collapse  Quote originally posted by hooray ...
I am a Javascript newb, and I am haveing some trouble with my arguments.
php Syntax (Toggle Plain Text)
  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.
php Syntax (Toggle Plain Text)
  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";
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript image slider issue
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: pass the value to the text box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC