Click to See Complete Forum and Search --> : Using a variable in a command
essaryj
01-29-2003, 05:46 PM
Here's what I want to do. In the code below, where it has "+ name +" I want that to be the value of the "name" variable, which is a string.
function swapover(name) {
document. + name + .src = + name + Over.src; return true;
}
I have no idea if this is even possible. TIA!!!!
essaryj
01-30-2003, 12:49 PM
Below is a simplified version of what I have going on. I changed it how Dave said to, and it still isn't working. Is there something else that I have done wrong? Maybe with this you'll be able to give me a better response without guessing what I'm doing.
TIA!!!
<SCRIPT LANGUAGE="JavaScript">
<!-- hide from none JavaScript Browsers
calendarOver = new Image()
calendarOver.src = "images/calendarover.gif"
calendarOut = new Image()
calendarOut.src = "images/calendarout.gif"
function swapover(name) {
document.images[name].src = window[name + "Over"].src; return true;
}
function swapout(name) {
document.images[name].src = window[name + "Out"].src; return true;
}
// - stop hiding -->
</SCRIPT>
</head>
<body bgcolor="black">
<a href="calendar.asp" onMouseOver="swapover(calendar)" onMouseOut="swapout('calendar')">
<img name="calendar" src="images/calendarout.gif" border=0></a><BR>
essaryj
01-30-2003, 12:51 PM
This line should be written as it is below, not as I originally posted it.
<a href="calendar.asp" onMouseOver="swapover(calendar)" onMouseOut="swapout(calendar)">
Webskater
01-30-2003, 01:11 PM
To concatenate a variable with some text to produce a new variable you need to use eval:
newname = eval(name + "Over")
essaryj
01-30-2003, 01:43 PM
nah, it worked as is, I just sent the var to the function wrong. I needed swapOver('calendar') instead of swapOver(calendar) but I thought I tried it like that. It works now. Thanks again Dave.