Click to See Complete Forum and Search --> : changing a var onmouseover
sumyounguy
07-22-2003, 04:15 PM
hi, if i have
var person=1;
in my head, and i want to change person to 3 on a mouseover
how would i go about doing that?
I tried person=3, and var person=3 with no effect
Like this:
<script type="text/javascript">
person = 1;
</script>
</head>
<body>
<a href="#" onmouseover="person=3;">change</a>
sumyounguy
07-22-2003, 04:26 PM
Hmm...its very likely that i'm retarded, but its not working with this code, think ya could help me out...
<html>
<head>
<title>MSD Web</title>
<style>
p:{cursor:normal}
</style>
<script language="JavaScript">
person=0;
</script>
</head>
<body>
<table width="100%">
<tr>
<td width=33% id="DRGtab" align="center"
onmouseover="staffimg.src='DrGregory.jpg';staffimg.height=354;staffimg.width=250;DRGtab.style.background='#a
bbbbf';person=1" style="cursor:normal;border:1px dashed #abcdef"
onmouseout="DRGtab.style.background='white'">
<div style="cursor:default">Dr. Richard Gregory</div>
</td>
<td width=33% id="sandytab"
align="center"onmouseover="staffimg.src='Sandy.jpg';staffimg.height=354;staffimg.width=250;sandytab.style.ba
ckground='#abbbbf';person=2" style="cursor:normal;border:1px dashed #abcdef"
onmouseout="sandytab.style.background='white'">
<div style="cursor:default">Sandy Heath</div>
</td>
<td width=33% align="center" id="shartab"
onmouseover="staffimg.src='Sharon.jpg';staffimg.height=354;staffimg.width=250;shartab.style.background='#abb
bbf';person=3" style="cursor:normal;border:1px dashed #abcdef"
onmouseout="shartab.style.background='white'">
<div style="cursor:default">Sharon Rowlett</div>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<img src="" height=0 width=0 name="staffimg">
</td>
</tr>
<tr>
<td width=100% colspan=3 align="center">
<script>
document.writeln(person);
if(person==2)
{
document.writeln("yada yada");
}
</script>
</td>
<tr>
</table>
diamonds
07-22-2003, 04:55 PM
well, for one, you may not be setting it correctly! put this before all code that requires the variable to be changed:
<script>
var myvar = '';
</script>
this declares the variable before it goes into any functions, so it does not get "deleted" by javascript when the function ends!
make sure you use this along with pyrro 's code, too!
[COLOR=red]ohh, thunder-storm. gotta go!
sumyounguy
07-22-2003, 05:07 PM
nevermind, the variable was changing correctly from the get-go, the page just wasn't updating properly