rw****@gmail.com wrote:
rws...@gmail.com wrote:
This works in firefox, not at all in ie6. I'm not getting any errors,
but only the doalert() function works, not the click() function. I'm
sure there's something obvious, but I'm just not seeing it. Help would
be greatly appreciated.
Sorry! The codine must be working. Here's the code:
<html>
<head>
<script type="text/javascript">
function click() {
This creates a property of the global object called 'click'.
var div = document.getElementById("test");
var input = document.getElementById("hidden_input");
div.innerHTML = "changed";
input.value = "changed";
alert(input.value);
}
function doalert() {
alert("alert");
}
</script>
</head>
<body>
<div id="test">id: test</div>
<input type="hidden" name="hidden" value="initial" id="hidden_input"
/>
<a href="#" onclick="doalert(); click();">test</a>
^^^^^^^
The HTML onclick attribute is used to associate script with the 'click'
event. How that happens in IE is different to other browsers.
In IE, if an element has an onclick attribute, it's equivalent DOM
object is given a hidden[1] 'click' property which will mask your click
function that is attached to the global object higher up the scope chain.
In Firefox, the element doesn't have a click property (the event model
is quite different to IE's) so the global click() function runs.
1. The 'click' property is not enumerable, it's not shown when using
using for..in, but can be seen if accessed explicitly using:
<div onclick="alert(this.click);">...</div>
In Gecko browsers the above shows 'undefined', in IE it shows:
function click(){
[native code]
}
--
Rob