
May 4th, 2008, 12:10 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 14
  
Time spent in forums: 1 h 37 m 40 sec
Reputation Power: 0
|
|
|
Trouble passing variable on event to function
Here's my problem. I'm creating a type of scrolling function for different html objects. Anyways, i want to make the javascript function usable on a bunch of different objects. The trouble i'm having is passing variables through all the quotes on an event. Here's the code:
Code:
<script type="text/javascript">
// How much to shift each time
var shDist = 1;
// Set interval in ms, and interval variables
var intv = 10;
var r;
var l;
function scRight(x)
{
var scBod = document.getElementById(x);
scBod.scrollLeft = scBod.scrollLeft + shDist;
}
function scLeft(x)
{
var scBod = document.getElementById(x);
scBod.scrollLeft = scBod.scrollLeft - shDist;
}
</script>
<html>
<body>
<button id="Larrow" onmouseover="l=setInterval('scLeft(main)',intv)" onmouseout="clearInterval(l)"><--</button>
<br />
<div id="main" style="overflow: hidden; border: 2px solid; width: 300px; height: 50px;">this is just garbage to make it scrollable arpjeiajrpeiajrpiejarpiejarpejaripjeapirjepairjepairjepajriepajrieojarpejaignhioejarijeaporjeaprijea pojrepajrepajreiajriepajriearjeipajrepiajnnaoirjeioapjibjaioerjpaoejtijaibhgairejiepajgiaenrijeairpj eiaopjnhaknbaegonapeoirjaewinhiantiea</div>
<br />
<button id="Rarrow" onmousedown="r=setInterval('scRight(main)',intv)" onmouseup="clearInterval(r)">--></button>
</body>
</html>
Any advice on what i should do to pass the "main" id to the scRight and scLeft functions?
|