...

View Full Version : javascript events in firefox versus ie



haegens_nico
01-24-2005, 04:14 PM
Hello,
I am making a java servlet that generates a menu. It's to difficult to determine the exact browser in java. However, I made one in javascript. Depending on the browser(IE supports by default the onclick and onchange event), I have to make my admin menu for IE & other browsers that don't support it by default. It are a few dozen buttons that should listen to click events and a few dozen text fields(input type=text) that should listen to change events. Now here is my problem: they don't listen to the events, not change events or click events.
I have three browsers that I have tested it on: Mozilla 5.0, FireFox/1.0 & IE6. The only one that executes it normally is IE6. Here is my script:
function doAction()
{
var oSource=window.event.srcElement;
var iden=oSource.name;
window.open("/servlet/menus.DBMenuUpdate?dbname=haegens_vva&operation="+iden,"_self");
}
function capture()
{
document.captureEvents(Event.CLICK);
document.onclick=doAction;
document.onchange=saveChange;
}
function saveChange()
{
var oSource=window.event.srcElement;
var naam=oSource.name;
var waarde=oSource.value;
var newobj=document.createElement("input");
var counter=commands.childNodes.length;
newobj.type="hidden";
newobj.name="command"+counter;
newobj.value="Change "+naam+" To "+waarde;
var obj=commands.insertAdjacentElement("beforeEnd",newobj);
}
the function capture() is called here:
<body onload="capture();">
the function doAction() should be called here:
<input type="button" id="cmdVerwijderen12" name="cmdVerwijderen12" onclick="doAction()">
the function saveChange() is called here:
<input name="txtLink110" onChange="saveChange()" type="text" value="Prov_Antwerpen.htm" size="50" maxlength="50">.
Can someone please help me out?

hemebond
01-25-2005, 12:03 AM
captureEvents is IE-only.

haegens_nico
01-25-2005, 09:39 AM
Actually, the place where I got it from, claims it's for netscape. That's why I used that code. Of course, my source could be mistaken.

haegens_nico
01-25-2005, 01:53 PM
I found out why it didn't work:
1.) window.event has no methods in firefox.
2.) I had to define "commands" first before I could use it, even if it has an id.
3.) insertAdjacentElement is not a method supported by firefox.
here is my altered code:
function eventTrigger (e)
{
if (! e)
e = event;
return e.target || e.srcElement;
}
function saveChange(e)
{
var oSource=eventTrigger(e);
var naam=oSource.name;
var waarde=oSource.value;
var newobj=document.createElement("input");
var commands=document.getElementById("commands");
var counter=commands.childNodes.length;
newobj.type="hidden";
newobj.name="command"+counter;
newobj.value="Change "+naam+" To "+waarde;
var obj=commands.appendChild(newobj);
return true;
}
function doAction(e)
{
var oSource=eventTrigger(e);
var iden=oSource.name;
if(oSource.type=="button")
window.open("/servlet/menus.DBMenuUpdate?dbname=haegens_vva&operation="+iden,"_self");
return true;
}
here is the html code:
<input type="text" onChange="return saveChange(event)" name="txtNaam00" value="Actief/LID worden"></td></tr>
<Input Type=Button Name=cmdWijzigen13 value="Wijzigen" onClick="return doAction(event)">

glenngv
01-26-2005, 02:03 AM
captureEvents is IE-only.
It's NS4 only.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum