Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms[0] error 1

Status
Not open for further replies.

ksoong

Programmer
Oct 3, 2000
57
CA
Hi all,

I am working on a server that has a predefined form page.
The form page follows like:

<form action=blah.cgi method=post>
<input type=hidden name=name value=&quot;Mr. Jones&quot;>
</form>

There is no name in the form and I can't change that predefined form to have a name. I want to do this.

<script>
alert(&quot;Hi there &quot;+document.forms[0].name.value);
</script>

But it's giving me an error that says:

document.forms.0.name is null or not an object

why is this not working? according to javascript specs this should work shouldn't it?

Kenneth
 
Hi Kenneth,

What you need to do is to load the form first or put the <script> after the form

Try the following..

solution 1
------------
<html>
<head>
<script>
function setDefault() {
alert(&quot;Hi there &quot;+document.forms[0].name.value);
}
</script>
</head>
<body onload=&quot;setDefault()&quot;>
<form action=blah.cgi method=post>
<input type=hidden name=name value=&quot;Mr. Jones&quot;>
</form>
</body>
</html>

or

solution #2
------------
<html>
<body>
<form action=blah.cgi method=post>
<input type=hidden name=name value=&quot;Mr. Jones&quot;>
</form>
<script>
alert(&quot;Hi there &quot;+document.forms[0].name.value);
</script>
</body>
</html>


hope this helps.. =)
Chiu Chan
cchan@emagine-solutions.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top