Click to See Complete Forum and Search --> : eval


IxxI
02-06-2003, 10:44 AM
I am currently using this javascript call as the mouse passes over a button to show some text in a div box in a different frame:

var setup = "Do this do that etc."

function showbox() {
if(window.top.iframe.main.document.getElementById("mainbox")){
window.top.iframe.main.document.getElementById("mainbox").style.visibility = "visible";
window.top.iframe.main.document.getElementById("mainbox").innerHTML = setup;
}
else{}
}

Problem is I have one of these for each button so the code is quite long, and I was wondering if there was any way to use the eval command to have one javascript call with mulltiple variables as opposed to multiple javascript calls. My code works fine - its just an aesthetic thing. I've tried changing my code to:

function showbox(text) {
if(window.top.iframe.main.document.getElementById("mainbox")){
window.top.iframe.main.document.getElementById("mainbox").style.visibility = "visible";
window.top.iframe.main.document.getElementById("mainbox").innerHTML.value = eval(text);
etc.

and writing onMouseover="showbox('setup')" into my link, but it doesn't seem to work. Any suggestions?
IxxI

khalidali63
02-06-2003, 10:54 AM
If I understood your question correctly,then replace your emptytest.html page completely with this code below


<HTML>
<HEAD>
<STYLE type="text/css">
<!--
A { text-decoration:none }
-->
</STYLE>
<script>
var page1 = "This should appear when mouse moves over the link to page 1."
var page2 = "This should appear when mouse moves over the link to page 2."
var page3 = "This should appear when mouse moves over the link to page 3."
var page4 = "This should appear when mouse moves over the link to page 4."
var page5 = "This should appear when mouse moves over the link to page 5."
var page6 = "This should appear when mouse moves over the link to page 6."

function showbox(val) {
var url = parent.frames["main"].location.href;
//alert(url)
if (url.indexOf("test.html") > (-1) &&
window.top.iframe.main.document.getElementById("mainbox")) {
window.top.iframe.main.document.getElementById("mainbox").style.visibility = "visible";
window.top.iframe.main.document.getElementById("mainbox").innerHTML = "page"+val;
} else {
alert("Not the right window!");
}
}

function hidebox() {
var url = parent.frames["main"].location.href;
if (url.indexOf("test.html") > (-1)) {
window.top.iframe.main.document.getElementById("mainbox").style.visibility = "hidden";
} else {
alert('Not the right window!');
}
}
</script>

</HEAD>
<BODY topmargin="4" leftmargin="0" rightmargin="0" BGCOLOR="#C0C0C0" TEXT="#0F0000" ALINK="#0F0000" VLINK="#0F0000" LINK="#000000">
<font face="times new roman" size="5">
<CENTER>
<A HREF="error.html" target="main" onMouseover="showbox(1)" onMouseout="hidebox()">Page 1</A>
/
<A HREF="error.html" target="main" onMouseover="showbox(2)" onMouseout="hidebox()">Page 2</A>
/
<A HREF="error.html" target="main" onMouseover="showbox(3)" onMouseout="hidebox()">Page 3</A>
/
<A HREF="error.html" target="main" onMouseover="showbox(4)" onMouseout="hidebox()">Page 4</A>
/
<A HREF="error.html" target="main" onMouseover="showbox(5)" onMouseout="hidebox()">Page 5</A>
/
<A HREF="error.html" target="main" onMouseover="showbox(6)" onMouseout="hidebox()">Page 6</A>
</CENTER>
</BODY>
</HTML>

IxxI
02-07-2003, 04:03 AM
Thanks for the replies. Dave you'll be surprised to hear that it didn't work, however once I removed the .value it did! Dunno why that should happen but there you go. Thanks again,
IxxI

IxxI
02-07-2003, 06:22 AM
Makes sense now, cheers.
IxxI