PDA

Click to See Complete Forum and Search --> : Using variables passed to a function


hall
Mar 1st, 2001, 05:58 AM
<!--

Help!! See below. I am trying to pass a variable (option) to a function, which in this case is the id of a paragraph (i.e., "test_paragraph"). I'd like for the function then to turn off the display of the test_paragraph based on the passed variable (option). The id gets passed Ok as witnessed by the alert message. However, it will not work using the option.style.display="none"; whereas it will work if you type the actual name of the paragraph as shown in command that is not commented out (test_paragraph.style.display="none";). Is this a syntax problem? Since I'm not a javascript person, a potentially small syntax problem shuts me down. Thanks very much in advance.

KBH

-->




<SCRIPT>
function turn_paragraph_off(option)
{
alert(option)

test_paragraph.style.display="none";

// option.style.display="none";

}
</SCRIPT>

<%variable="test_paragraph"%>
<P onmouseover="turn_paragraph_off('<%=variable%>')" >
Move the mouse over this sentence make the test paragraph below turn off.
</p>

<br>
<br>
<br>


<p id=test_paragraph >
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
</p>

Mar 1st, 2001, 07:51 AM
Hi, of course you can use a dirty way to do it and just create a small function for every different paragraph. But I guess you don't really wanna do that, huh? ;)

I have done it before, but since I'm no expert on javascript either, I forgot exactly how. I do remember you have to go through the object model to get to it, so something like:

window.document.items(option).style.display = "none";

Of course that's not the right line (I think) but that's the direction you gotta search in..

jdavison
Mar 1st, 2001, 08:40 AM
try document.formname.item[option].style.display = "none";
atleast i think thats it:)

monte96
Mar 1st, 2001, 02:05 PM
<HTML>
<HEAD>
<SCRIPT language=Javascript>
function turn_paragraph_off(option)
{
alert(option)

if (document.all[option].style.display=="none")
document.all[option].style.display = "";
else
document.all[option].style.display = "none";
//test_paragraph.style.display="none";

// option.style.display="none";

}
</SCRIPT>
</HEAD>
<BODY>
<%variable="test_paragraph"%>
<P onmouseover="turn_paragraph_off('<%=variable%>')" >
Move the mouse over this sentence make the test paragraph below turn off.
</p>

<br>
<br>
<br>


<p id=test_paragraph >
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
<br>
TEST TEST TEST TEST TEST TEST TEST TEST TEST
</p>
</BODY>
</HTML>

jdavison
Mar 1st, 2001, 02:37 PM
guess your not using forms doh. try changing paragraph from id to name. i have had problems with using id in the past, especially in netscape