Shoutbox

Javascript variable help[solved] - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Javascript variable help[solved] (/showthread.php?tid=56033)

Javascript variable help[solved] by QtanJ on 02-19-2006 at 08:12 PM

I have a IPB forum v.2 and want a spoiler tag. Since I don't want to modify my IPB forum yet, I want to use custom bbcode. I've got this code, but don't have a clue of how I make a variable decide what id number every spoiler need.

code:
<script language="JavaScript" type="text/JavaScript">
<!--
function toggleVisibility(obj)
{
      var Value=Math.random()*57568745757456
     document
if (obj!=null)
{
if (document.getElementById)
{
var current = (document.getElementById(obj).style.display == 'block') ? 'none' : 'block';
document.getElementById(obj).style.display = current;
}
else if (document.all)
{
var current = (document.all[obj].style.display == 'block') ? 'none' : 'block'
document.all[obj].style.display = current;
}
}
}
//-->
</script>
<p>
<a href="javascript:toggleVisibility('Value')">Spoiler</a>
</p>

<div id='Value' style="display:none;">
<p style="background-color:FF0000;FONT-SIZE: 24pt;">
{content}
</p>
</div>

{content} is right, i've testen and that part works.

If I make it {option} then I can make something like this to get it work with more than one each page
code:
Spoiler for somethingunique:
What I want in spoiler

What's wrong with this solution is:
1. You have to write something unique after = in every spoler tag
2. If you quote you need to change the id of the spoiler if you don't want the second spoiler to be a remote control of the first one.


The random number don't have to be a random number multiplied with that numeber i chose there, but it needs to have many choices since i don't like remote controls.

To test if your solution works, just make a html file with two or more spoilers and check if the second one works and that it isn't a remote control.

As the code is now it should work once in each page since the id of every spoiler is value.


Thanks for every answer.

RE: Javascript variable help. by ShawnZ on 02-19-2006 at 08:16 PM

Almost impossible to do without modifying IPB. you'd at least need to convert them to DIVs with IDs before you can do anything useful with them.


RE: Javascript variable help. by QtanJ on 02-19-2006 at 10:28 PM

I've managed to make it. The sourcecode looks like a mess, but at least it works. Feel free to use it as you like as long as you want.

code:
<script language="JavaScript" type="text/JavaScript">
<!--
function toggleVisibility(obj)
{
     
     document
if (obj!=null)
{
if (document.getElementById)
{
var current = (document.getElementById(obj).style.display == 'block') ? 'none' : 'block';
document.getElementById(obj).style.display = current;
}
else if (document.all)
{
var current = (document.all[obj].style.display == 'block') ? 'none' : 'block'
document.all[obj].style.display = current;
}
}
}
var Value = Math.random()*57568745757456;
document.write("<a href=");
document.write('"javascript:toggleVisibility(');
document.write("'");
document.write(Value);
document.write("')");
document.write('">Spoiler</a>');

document.write("<div id=");
document.write("'");
document.write(Value);
document.write("'");
//-->
</script>
style="display:none;">
<p style="background-color:FF0000;FONT-SIZE: 24pt;">
{content}
</p>
</div>

Sorry, I didn't express myself how I needed help clear enough, but case solved.
RE: Javascript variable help[solved] by -dt- on 02-20-2006 at 03:31 AM

wtf is with the document.write ewwww  , have you heard of using document.createElement and then appendChild it into the document.


RE: Javascript variable help[solved] by QtanJ on 02-20-2006 at 01:58 PM

Actually no. Javascript isn't the computer language I know best. When it's about websites I usually program in PHP, but in this case I couldn't use it.

It works, and then I have no need to use functions I didn't find in the guides I searched for when I tried to solve this problem.

I don't think I can ever use the easy solutions that needs 20 minutes every time  you loose the modified file or uprgrade, instead of making a code that takses seconds to install when you first have the code.


Thanks for trying to help both of you.