HTML form Control event handling

Hi Can anybody help me to correct this one?

I am getting error message "document.form.Test2" is null or not an object.

I am new to HTML and Scripting.

<html>
<title>JAVASCRIPT</title>

<script language = "JavaScript" type="text/javascript">

function CalculateTotalImpact(){

alert( document.form.Test2.value);

}
</script>

<BODY>

<input id="Test1" type="text" value = "" onchange = "CalculateTotalImpact()" />
<input id="Test2" type="text" value = "" onchange = "CalculateTotalImpact()" />
<INPUT TYPE="button" ONCLICK="CalculateTotalImpact()" VALUE="click to say hello">

</BODY>
</HTML>

Thank you. :wave:

Amit
[810 byte] By [AmitInnani] at [2007-11-19 23:17:52]
# 1 Re: HTML form Control event handling
You need a form tag around your input fields for them to be considered a form.
http://www.w3.org/TR/html4/interact/forms.html

<form name="myForm" method="post" action="www.someplace.com">
//your input fields here
</form>

then you can access the fields:
document.myForm.myInputField
Alsvha at 2007-11-8 0:40:31 >
# 2 Re: HTML form Control event handling
Yes Alsvha is correct as usual!
You could try something like:
<HTML>
<HEAD>
<TITLE>JAVASCRIPT</TITLE>
</HEAD>

<script language = "JavaScript">

function CalculateTotalImpact(){

alert( document.form.Test2.value);

}
</script>

<BODY>
<FORM>
<input id="Test1" type="text" value = "" onchange = "CalculateTotalImpact()" >
<input id="Test2" type="text" value = "" onchange = "CalculateTotalImpact()" />
<INPUT TYPE="button" ONCLICK="CalculateTotalImpact()" VALUE="click to say hello">
</FORM>
</BODY>
</HTML>

Give that a try.
I just have a couple of issues with your code.

The Head tag- I'm old fashioned, but it makes for better proper reading when included

You don't have to say: <script language = "JavaScript" type="text/javascript">

You could use either
<script language = "JavaScript">
or
<script type="text/javascript">

As far as I know the language attribute will eventually be replaced with : type="text/javascript", so it's actaully better to use it instead of language.

<input id="Test1" type="text" value = "" onchange = "CalculateTotalImpact()" />

I may be wrong, but the Input tag is not a container tag, meaning that it doesn't have a closing tag. You don't need to include the "/" in there it just needs to be:
<input id="Test1" type="text" value = "" onchange = "CalculateTotalImpact()" >

I hope these comments were useful
HanneSThEGreaT at 2007-11-8 0:41:27 >