• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding document object in javascript

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everybody,

Here is my code:

-----------------------------------------------------------
<body>
<form name="form1">
<input type=text name="text1" value="">
<script language="JavaScript">
document.form1.text1.value="Hello";
</script>
</form>
</body>
-----------------------------------------------------------

As shown above, if I use form name to set a value in a text box, it is working fine. But if I use document.Forms(0) as shown below, the value "Hello" is not getting set to that text box. See the following code:

-----------------------------------------------------------

<body>
<form>
<input type=text name="text1" value="">
<script language="JavaScript">
document.Forms(0).text1.value="Hello";
</script>
</form>
</body>
-----------------------------------------------------------

Can anybody say what could be the problem?

Thanks
------
Shashi
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there Shashi,

There are a couple of things that may be involved.

First, 'Forms(0)' would refer to a function, Forms(), which is taking an argument, 0.

What you need to refer to, is the array containing all forms in the page. To dereference the array, you need to use brackets:

Forms[0]

Also, I don't know on your system, but on mine, Forms[0] doesn't exist. I need to refer to it using all lower case:

forms[0]

But from experience, case-sensitivity may vary from platform to platform.
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Katrina,

I meant forms array. Thank you!! Now I tried using forms[0], it is working fine. In my system also Forms[0] is not working.

And..What does Forms(0) function do?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shashi Kala:
And..What does Forms(0) function do?


It gives you a JavaScript error, because it doesn't exist...
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Thank you Jesper Young

With Regards,
Shashi kala
 
reply
    Bookmark Topic Watch Topic
  • New Topic