Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Nested Variables & If...Elses?
Old 03-21-2010, 09:12 PM Nested Variables & If...Elses?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Hello,

I am having some trouble with the following code:

Code:
<script type="text/javascript">

function navsi(appear) {
  if(appear == "in"){
    document.getElementById("navsi").style.display="block";
  }
  else {
    document.getElementById("navsi").style.display="none";
  }
}

</script>

<ul>
<li onmouseover="navsi(in)" onmouseover="navsi(out)">Hover Me!!</li>
<div id="navsi" style="display:none;">Hi there!!</div>
</ul>
I want it so when you hover over the text 'Hover Me!!', it shows the text "Hi there!!", and when you remove your mouse, it hides it again.

Of course, I could do this with two functions, but that wastes space, so I was wondering if this was possible?

Thanks,

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2010, 07:20 AM Re: Nested Variables & If...Elses?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You have 2 "onmouseover" events. Your second should be "onmouseout":
HTML Code:
<html>
    <body>
    <script type="text/javascript">
    function navsi(state) {
        if(state==1){
            document.getElementById('navsi').style.display="block"
        }else{
            document.getElementById('navsi').style.display="none"
        }
    }
</script>

<ul>
<li onmouseover="javascript:navsi(1)" onmouseout="javascript:navsi(0)">Hover Me!!</li>
<div id="navsi" style="display:none;">Hi there!!</div>
</ul>
    </body>
</html>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-22-2010, 09:51 AM Re: Nested Variables & If...Elses?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Also, with your original function you'll have to either to it with 1,0 like Tripy, or else put single quotes around your arguments. The way you're passing the (in), (out), the it looks as if you expect there to be a two variables named in, out, and are passing those. Try ('in'), ('out'). You could also just pass (true), (false) and test for that.

HTML Code:
<script type="text/javascript">

function navsi(appear) {
  if(appear){
    document.getElementById("navsi").style.display="block";
  }
  else {
    document.getElementById("navsi").style.display="none";
  }
}

</script>

<ul>
<li onmouseover="navsi(true)" onmouseout="navsi(false)">Hover Me!!</li>
<div id="navsi" style="display:none;">Hi there!!</div>
</ul>
Putting DIV within a UL without wrapping it in a LI is not valid code, and might cause problems in different browsers.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 03-22-2010 at 09:54 AM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-22-2010, 03:36 PM Re: Nested Variables & If...Elses?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Thank you both of you!

I have fixed it, all I did was put single quotes around the "navsi('in')" and changed the second onmouseover to onmouseout! Now it works; thank you!!!!!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Nested Variables & If...Elses?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36119 seconds with 12 queries