what's wrong with this code?

  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

Code: [ Select ]
<script type="text/javascript">
var i=-150
var intHide
var speed=3
var which_menu
function showmenu(which_menu)
{
clearInterval(intHide)
intShow=setInterval("show(which_menu)",5)
}
function hidemenu(which_menu)
{
clearInterval(intShow)
intHide=setInterval("hide(which_menu)",5)
}
function show(which_menu)
{
if (i<-12)
    {
    i=i+speed
    document.getElementById('which_menu').style.left=i
    }
}
function hide(which_menu)
{
if (i>-150)
    {
    i=i-speed
    document.getElementById('which_menu').style.left=i
    }
}
</script>
  1. <script type="text/javascript">
  2. var i=-150
  3. var intHide
  4. var speed=3
  5. var which_menu
  6. function showmenu(which_menu)
  7. {
  8. clearInterval(intHide)
  9. intShow=setInterval("show(which_menu)",5)
  10. }
  11. function hidemenu(which_menu)
  12. {
  13. clearInterval(intShow)
  14. intHide=setInterval("hide(which_menu)",5)
  15. }
  16. function show(which_menu)
  17. {
  18. if (i<-12)
  19.     {
  20.     i=i+speed
  21.     document.getElementById('which_menu').style.left=i
  22.     }
  23. }
  24. function hide(which_menu)
  25. {
  26. if (i>-150)
  27.     {
  28.     i=i-speed
  29.     document.getElementById('which_menu').style.left=i
  30.     }
  31. }
  32. </script>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

what is the code supposed to do?

sorry might be a stupid question. Are you trying to put a timer on your menus or something?
  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

I'm trying to tweak this menu http://www.w3schools.com/dhtml/tryit.asp?filename=trydhtml_menu_slidehorizontal

So that I can have more than one menu without creating a custom function for each[/url]
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Are there supposed to be quotes in this line ?
document.getElementById('which_menu').style.left=i
  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

From a php point of view, no, but I don't really know, I don't have any motivation to hardcore learn the javascript language, I do php instead.

What I'm trying to do, is forward the variable from one function to another, but it doesn't seem to be working either way.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

joebert is right about the quotes in the getElementById's. There's a second problem with passing arguments to the function that will be called repeatedly be setInterval. If you want it to pass by value you need to concatenate the variable inside the string that is being passed to setInterval, so that the variable name will be replaced with the value.

I tried making the necessary syntax changes and got it running, but I think you're still going to run into logical problems when onmouseover happens on a second menu while one is still in motion. I have little experience with these kinds of menus, so I'm not sure offhand how to solve that problem.

Code: [ Select ]
<script type="text/javascript">
var i=-150
var intHide
var speed=3

function showmenu(which_menu)
{
    clearInterval(intHide);
    intShow=setInterval("show('" + which_menu + "')",5);
}
function hidemenu(which_menu)
{
    clearInterval(intShow);
    intHide=setInterval("hide('" + which_menu + "')",5);
}
function show(which_menu)
{
if (i<-12)
  {
  i=i+speed;
  document.getElementById(which_menu).style.left=i;
  }
}
function hide(which_menu)
{
if (i>-150)
  {
  i=i-speed;
  document.getElementById(which_menu).style.left=i;
  }
}
</script>
  1. <script type="text/javascript">
  2. var i=-150
  3. var intHide
  4. var speed=3
  5. function showmenu(which_menu)
  6. {
  7.     clearInterval(intHide);
  8.     intShow=setInterval("show('" + which_menu + "')",5);
  9. }
  10. function hidemenu(which_menu)
  11. {
  12.     clearInterval(intShow);
  13.     intHide=setInterval("hide('" + which_menu + "')",5);
  14. }
  15. function show(which_menu)
  16. {
  17. if (i<-12)
  18.   {
  19.   i=i+speed;
  20.   document.getElementById(which_menu).style.left=i;
  21.   }
  22. }
  23. function hide(which_menu)
  24. {
  25. if (i>-150)
  26.   {
  27.   i=i-speed;
  28.   document.getElementById(which_menu).style.left=i;
  29.   }
  30. }
  31. </script>
  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

Now it says there is a syntax error with this!
Arggg:
Code: [ Select ]
<table id="legion" class="nav" width="165" onmouseover="showmenu("legion")" onmouseout="hidemenu("legion")">



here is the rest of the table:


Code: [ Select ]
<tr>
<td class="menu"><a href="./legion/join.html">Join</a></td>

<td rowspan="5" align="center" bgcolor="#FF8080">L<br>E<br>G<br>I<br>O<br>N</td>
</tr>

<tr>
<td class="menu"><a href="./legion/about.html">About</a></td></tr>
</table>
  1. <tr>
  2. <td class="menu"><a href="./legion/join.html">Join</a></td>
  3. <td rowspan="5" align="center" bgcolor="#FF8080">L<br>E<br>G<br>I<br>O<br>N</td>
  4. </tr>
  5. <tr>
  6. <td class="menu"><a href="./legion/about.html">About</a></td></tr>
  7. </table>



Thanks for the help Rich!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

First is yours, notice the difference ?
Code: [ Select ]
onmouseover="showmenu("legion")"


Code: [ Select ]
onmouseover="showmenu('legion')"


using " instead of ' in the middle causes the browser to see this onmouseover="showmenu(" then legion is interpreted as a syntax error.
  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

YAYYYYYYYYYYYYYYYYYYY

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.