Offm wrote:
I was trying to make some experiences with javascript ,
making a div response to a text input but cannot say what am doing bad so
if anyone could help with the script,
many Thanks
the script follows
<script type="text/javascript">
function I(form)
{
if(form.e2.value=="")
document.getElementById("dc").innerHTML="something ";
}
</script>
<p >
<form name="form">
<input name="e2" size="20" type="text">
<select name="e1">
<option>option.....
<option>option1
</select>
<input src="" onclick="I(form)" align="right" type="image" width="60"
height="49"></p>
Hi, You are sending form to the function.
To debug your code, simple alert your parameters and see what JavaScript say
they are.
In your case:
<script type="text/javascript">
alert ("Received form. form="+form);
function I(form)
{
if(form.e2.value=="")
document.getElementById("dc").innerHTML="something ";
}
</script>
It will probably yell something like 'undefined'.
To fix your script:
1) Make a valid reference to the form in your function
like:
var myForm = document.forms["form"];
or
2) Pass a valid reference to the function from the onClick-handler.
You can use the keyword 'this', but it will reference to the image, not the
form.
onClick='I(this);';
I would advise 1), and when you get a hang of it, you can start using
'this'. (I never use this for such purposes, and always build the reference
inside the function, but that is personal taste and total imcompetence on
my side.)
Regards,
Erwin Moller
</form>
<p> </p>
<div id="dc">
</div>