-
<!--
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>
-
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..
-
try document.formname.item[option].style.display = "none";
atleast i think thats it:)
-
Code:
<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>
-
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