PDA

View Full Version : problems with an Onclick event


usban
10-23-2002, 07:34 PM
What's wrong with this code?? it works perfectly in IE but the little image that acts as a link don't work in netscape 7.
<html>
<head>
<script>
function busca()
{
if(cadena.value!="")
parent.mainFrame.location = "general/buscar.php?cadena="+cadena.value;
else
return false;
}
</script>
<style type="text/css">
<!--
.icono {
cursor: hand;
}
-->
</style>
</head>
<body>
<table width="95%" border="0">
<tr>
<td><input name="cadena" type="text" size="10">
&nbsp;&nbsp; <img src="img/view.gif" class="icono" onClick="busca()">
</td>
</tr>
</table>
</body>
</html>

mordred
10-23-2002, 08:16 PM
NN7 / Mozilla is much more strict in regard to how DOM elements are exposed to the scripting engine. IE eats almost everything, which can lead itself to various problems, and because of that it should not be confused with the correct way to implement a functionality.

Here's a preliminary, corrected version.


<html>
<head>
<script>
function busca()
{
if (document.forms["bla"].elements["cadena"].value !="") {
parent.mainFrame.location.href = "general/buscar.php?cadena="+cadena.value;
}
else
return false;
}
</script>
<style type="text/css">
<!--
.icono {
cursor: hand;
}
-->
</style>
</head>
<body>
<table width="95%" border="0">
<tr>
<td>
<form name="bla">
<input name="cadena" type="text" size="10">
<img src="../scripts/explorer_view/images/folder.gif" class="icono" onclick="busca()" />
</form>
</td>
</tr>
</table>
</body>
</html>

premshree
10-24-2002, 07:46 AM
In your function "cadena" is not defined.........you cannot reference an object directly by it's name.....you must call it like this :

document.formName.elementName