Closed Thread Icon

Topic awaiting preservation: HELP!!! (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21322" title="Pages that link to Topic awaiting preservation: HELP!!! (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: HELP!!! <span class="small">(Page 1 of 1)</span>\

 
templar654
Bipolar (III) Inmate

From: Aiur, in the Tarsonian Galaxy
Insane since: Apr 2004

posted posted 04-13-2004 09:35

Hey guys I got some javascript problems. I'm trying to make something like this I have an image that when someone clicks on displays a paragraph of text(preferably in a table). This is what I have so far, here is the code I added to the image:

code:
<a href="javascript:;" onclick="toggleVis('paraOne', 'show');">
<img src="assets/images/new.gif" width="19" height="19" border="0"></a>



And here is the code I added to the paragraph:

code:
<p id="paraOne" style="display:none"> blah blah blah </p>



To me it all looks fine but the problem is it don't work I mean hey I did this before with text instead of an image and it worked like a charm now when you click on the image you don't see no paragraph. Can someone tell me where I'm goin' wrong?? Oh and another thing can anyone tell me how I can enter the paragraph in an external file and somehow link it to the page so I'd only have to edit the external file instead of editing the main file... did anyone get that?

... e'sssaa 'de templar'e ...

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-13-2004 11:01

well.... do you have the toggleVis() function actually defined? I don't see it in your code example.


As for the external file thing, the only way I see it to do this via javascript is an iframe.

(Edited by bitdamaged on 04-14-2004 14:01)

templar654
Bipolar (III) Inmate

From: Aiur, in the Tarsonian Galaxy
Insane since: Apr 2004

posted posted 04-13-2004 15:03

Hee hee.. I knew there was something missing Here's how it is, it works but I can't get that external file thingy. How do I get that going??

code:
<script>


var current = '';

var curr = ''


function toggleVis(id,vis) {


para = document.getElementById(id);

current ? curr = document.getElementById(current) : null;


if (vis == 'show') {

curr ? curr.style.display = 'none' : null

para.style.display = 'block';

current = id;

}

else {

para.style.display = 'none';

current = '';

}


}


</script>



... e'sssaa 'de templar'e ...

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-13-2004 15:04

templar654:Hi. You know it would help if you provided [edit update='removed a rant asking the source code of the toggleVis( ) function' /] better if you put the page online.

What kind of error message do you have if any ? I've tested your code with 3 paragraphs by putting the JS in the page and in an external file, and it worked in IE5.01, IE5.5, IE6.0 and FF0.8



(Edited by poi on 04-13-2004 06:16)

templar654
Bipolar (III) Inmate

From: Aiur, in the Tarsonian Galaxy
Insane since: Apr 2004

posted posted 04-13-2004 15:29

The problem is I can't get it in an external file. It's working fine when I put it in the main page but I can't seem to get it externally. I'm somewhat a beginner in JS and I just can't get anything externally!!

... e'sssaa 'de templar'e ...

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-13-2004 15:44

By externally, you mean like this :

index.htm

code:
<html>
<body>

<a href="javascript:;" onclick="toggleVis('paraOne', 'show');"><img src="assets/images/new.gif" width="19" height="19" border="0"></a>
<a href="javascript:;" onclick="toggleVis('paraTwo', 'show');"><img src="assets/images/new.gif" width="19" height="19" border="0"></a>

<p id="paraOne" style="display:none"> ONE blah blah blah </p>
<p id="paraTwo" style="display:none"> TWO blah blah blah </p>

</body>
<script type="text/javascript" src="functions.js">/* <- that line loads your external JS file */</script>
</html>



functions.js

code:
var current = '';
var curr = ''
function toggleVis(id,vis)
{
para = document.getElementById(id);
current ? curr = document.getElementById(current) : null;
if (vis == 'show')
{
curr ? curr.style.display = 'none' : null
para.style.display = 'block';
current = id;
}
else
{
para.style.display = 'none';
current = '';
}
}



Or the toggleVis( ) function is nested in a frame or iframe ? If so, you must replace document in the document.getElementById( ) statements by the 'location' of the frame nesting the elements you wanna show/hide. By something like parent.contentFrame.document.getElementById( ) for example.

Hope that helps, and if still don't, it'll be time to provide an URL.

_PS_ btw the toggleVis( ) function can be shrinked to

code:
var current=null
function toggleVis( id, vis )
{
if( current )
current.style.display = 'none'
if( current = document.getElementById(id) )
current.style.display = vis=='show'?'block':'none'
}





(Edited by poi on 04-13-2004 06:47)

paritycheck
Bipolar (III) Inmate

From:
Insane since: Mar 2004

posted posted 04-13-2004 18:26

Ok i have an external file now the problem is that i want the paragraphs in the file and not the code..

templar654
Bipolar (III) Inmate

From: Aiur, in the Tarsonian Galaxy
Insane since: Apr 2004

posted posted 04-13-2004 20:41

Ok i have an external file now the problem is that i want the paragraphs in the file and not the code..

sorry i used my brothers login instead

... e'sssaa 'de templar'e ...

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-13-2004 20:48

That's a whole nother world of hurt.

You can put the paragraphs in an external js file as variables

var para1= 'yadda yadda'

but for long paragraphs, unescaping it is going to be a pain.
You can also include the files using some sort of server side scripting. Can I ask why you want the paragraphs in external files? It would help with the answer.



.:[ Never resist a perfect moment ]:.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-13-2004 20:49

or you could use <iframes> to include the external paragraphs. See your favourite HTML reference for that one.

templar654
Bipolar (III) Inmate

From: Aiur, in the Tarsonian Galaxy
Insane since: Apr 2004

posted posted 04-14-2004 07:03

well the reason I need it in an external file is because then I'd have to write every single thing in the main page and that's going to make the file size enormous. I could use iframes but I don't want to use any in-page scrolling just clik on the button and read the para. I'll see what I can do about an url, I'll try to get on up soon.

... e'sssaa 'de templar'e ...

Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 04-14-2004 07:09
quote:
bitdamaged said:

You can put the paragraphs in an external js file as variablesvar para1= 'yadda yadda' but for long paragraphs, unescaping it is going to be a pain.



Cameron once suggested me to separate paragrahs withing variables by adding them to the original string.

You know, like:

var thiscrap = "<p>hahahahahahaahah</p>"+
"<p>morehahahahahahahahaahaha</p>";

__________________________________


Sexy Demoness cel

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 04-14-2004 08:46

Aloso placing content in external/internal js "write-statements" makes it invisible to searchengines, in that case it's better to keep it inside block-level elements that you hide and show.
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

« BackwardsOnwards »

Show Forum Drop Down Menu