954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Form Problem

I have a single form in my web page. The Form is defined as

<FORM action="somepage.asp" method="post" id="Form1" >

<INPUT TYPE="Text" Name="txt1" id="txt1" size=5 >

</FORM>


In a javascript function, when I am writing

document.Form1.txt1.value = 5 ;

I am getting an error "document.Form1.txt1 is invalid or null".

Instead if I write

document.forms[0].txt1.value = 5 ;

it is working fine. What is wrong with the first statement ? I am using Visual Interdev 6, in which the dropdown list that appears for a object method/properties, is showing Form1 as a property of document and txt1 as a property of Form1 when I press dot(.) after the object name.

aparnesh
Junior Poster
194 posts since Jul 2005
Reputation Points: 20
Solved Threads: 10
 

You don't have a "name" attribute for your form tag. However, depending on the doctype you're using, you may want to switch to standard DOM methods, such as document.getElementById() , which will alleviate such problems.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Thanks.

aparnesh
Junior Poster
194 posts since Jul 2005
Reputation Points: 20
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You