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.

Recommended Answers

All 2 Replies

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.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.