Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Small function wont work in Firefox

Status
Not open for further replies.

wilberforce2

IS-IT--Management
Jan 8, 2007
36
GB
Gurus

Could someone have a quick look at this function and explain why it is not working in firefox. I have tried it in IE and safari and it works fine.

Code:
<HTML>

<script language="javascript">
function mo(obj) 
{
      if((obj.offsetWidth-event.clientX)<10)return
      var o; 
      
			var s= Math.round(event.offsetY / (((o=document.getElementById("test")).offsetHeight-6) / o.size));
      
			obj.selectedIndex=s;
      
			//document.getElementById("say").innerHTML = s;
			document.getElementById("say").innerHTML = document.getElementById("test").options[s].text
}
</script>


<form>
<select id="test" size=3 onmousemove="mo(this);">
 <option>one</option>
 <option>two</option>
 <option>three</option>
 <option>four</option>
</select>
<div id="say"></div>
</form>

</HTML>

Many thanks.
 
You have to pass event as a parameter in FF. This will work in all browsers.

Code:
onmousemove="mo(this[!], event[/!]);">

function mo(obj[!], evt[/!]) 
{
      if((obj.offsetWidth-[!]evt[/!].clientX)<10)return
      var o; 
      
            var s= Math.round([!]evt[/!].offsetY / (((o=document.getElementById("test")).offsetHeight-6) / o.size));
      
            obj.selectedIndex=s;
      
            //document.getElementById("say").innerHTML = s;
            document.getElementById("say").innerHTML = document.getElementById("test").options[s].text
}

[monkey][snake] <.
 
Thanks you for your prompt response.

I am still having problems where s is = NaN whatever that means?

Any ideas

Many thanks.
 
It means that s is [!]N[/!]ot [!]a[/!] [!]N[/!]umber.

I don't think .size is a Javascript method at all.
There's .width and .height.

I'm guessing o.size is returning undefined.

var o =
var s= Math.round(evt.offsetY / (((o=document.getElementById("test")).offsetHeight-6) / o.size));


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top