If conditions and some other stuffs

it doesn't work the way i want it to be.

Page 1 of 1

9 Replies - 684 Views - Last Post: 11 September 2010 - 08:19 AM

#1 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

If conditions and some other stuffs

Posted 11 September 2010 - 07:08 AM

here's my the code.

<html>
<head>
<script type="text/javascript">
function show(divid)
{
if(document.getElementById(divid).style.display == 'none')
{
document.getElementById(divid).style.display = 'block';
}
else
{
document.getElementById(divid).style.display = 'none';
}
}
</script>
</head>
<body>
<center>
<table>
<tr>
<td>
<tr><td><a href="" onclick="show(mydiv1)">Some text</a></td></tr>
<tr><td>
<div id="mydiv1" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
<tr><td><a href="" onclick="show(mydiv2)">Some text</a></td></tr>
<tr><td>
<div id="mydiv2" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
</td>
</tr>
</table>
</center>
</body>
</html>


now, the problem is. when i click the link. nothing happens. :| the way i want it to be is, when you click the link, the list shows. what's wrong with it?

Is This A Good Question/Topic? 0
  • +

Replies To: If conditions and some other stuffs

#2 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 07:30 AM

bump.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 07:44 AM

Patience, grasshopper! Twenty two minutes is a very small amount of time to expect a response.

What does this produce if in the beginning of your function?

alert(document.getElementById(divid).style.display);

Was This Post Helpful? 0
  • +
  • -

#4 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 07:48 AM

sorry about that. :/

about that alert. it doesn't even do it. :-? idk what's wrong.*it worked, but i didn't put it up, it shows "none"*

and, i've editted it. here's what i got.
<html>
<head>
<script type="text/javascript">
function show(divid)
{
if(document.getElementById(divid).style.display == 'none')
{
document.getElementById(divid).style.display = 'block';
}
else
{
document.getElementById(divid).style.display = 'none';
}
}
</script>
</head>
<body>
<center>
<table>
<tr>
<td>
<tr><td><a href="" onclick="show('mydiv1')">Some text</a></td></tr>
<tr><td>
<div id="mydiv1" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
<tr><td><a href="" onclick="show('mydiv2')">Some text</a></td></tr>
<tr><td>
<div id="mydiv2" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
</td>
</tr>
</table>
</center>
</body>
</html>


but, when you click it. it shows up and instantly hides it. i even used onmousedown.

This post has been edited by useletters: 11 September 2010 - 07:54 AM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 07:53 AM

And what does this do?

alert(divid.style.display);

Was This Post Helpful? 0
  • +
  • -

#6 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 07:58 AM

View PostCTphpnwb, on 11 September 2010 - 09:53 PM, said:

And what does this do?

alert(divid.style.display);

alert(document.getElementById(divid).style.display);

that shows "none"
alert(divid.style.display);

that doesn't show anything.
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 08:02 AM

View Postuseletters, on 11 September 2010 - 09:58 AM, said:

View PostCTphpnwb, on 11 September 2010 - 09:53 PM, said:

And what does this do?

alert(divid.style.display);

alert(document.getElementById(divid).style.display);

that shows "none"
alert(divid.style.display);

that doesn't show anything.

So do you think you should be using:
document.getElementById(divid).style.display

or
divid.style.display

?
Was This Post Helpful? 0
  • +
  • -

#8 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 08:08 AM

i should be using
document.getElementById(divid).style.display


my problem now is. how to keep the list being seen?.

i would like it to be this way.

when you click it on the first time, it shows the list, then if you click it again. it hides the list. it's like a show/hide button.
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 08:11 AM

Well, the way you have it you're attempting to send the element. If you want to use document.getElementById you need to put the id in quotes:
onclick="show('mydiv1')"

Your href needs to point to # to avoid refreshing the page.
<html>
<head>
<script type="text/javascript">
function show(divid)
{
	alert(document.getElementById(divid).style.display);
	if(document.getElementById(divid).style.display == 'none')
	{
		document.getElementById(divid).style.display = 'block';
	}
	else
	{
		document.getElementById(divid).style.display = 'none';
	}
}
</script>
</head>
<body>
<center>
<table>
<tr>
<td>
<tr><td><a href="#" onclick="show('mydiv1')">Some text</a></td></tr>
<tr><td>
<div id="mydiv1" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
<tr><td><a href="#" onclick="show('mydiv2')">Some text</a></td></tr>
<tr><td>
<div id="mydiv2" style="display:none">
<ul type="disk">
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
<li>Some text</li>
</ul>
</div>
</td></tr>
</td>
</tr>
</table>
</center>
</body>
</html>

This post has been edited by CTphpnwb: 11 September 2010 - 08:12 AM

Was This Post Helpful? 0
  • +
  • -

#10 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: If conditions and some other stuffs

Posted 11 September 2010 - 08:19 AM

THERE IT GOES! thank you very much for your help and time. :) i really appreciate it. thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1