• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing indexed properties in Javascript

 
Charanjit Sidhu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is basically a JavaScript question. I just have basic knowledge of Javascript. I have dynamically generated rows of input elements on my page which create indexed elements in the HTML. One of the example of an element is as follows:

<input type="text" name="escrowItems[0].disbAmount" value="0.0">

I am unable to access this element through javascript. The following doesn't work in a javascript function:

document.forms[0].escrowItems[0].disbAmount.value='';

Is it possible to handle it through Javascript? If yes, how?


Thanks!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any time you have a dot or square brackets in an html element name, you have to use a different syntax to access it. Try this format:

document.forms[0].item('escrowItems[0].disbAmount').value
 
Charanjit Sidhu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill. It works fine!

When I had this problem, I tried to search some JS tutorials and books but could not find the solution.

Can you suggest some good tutorial and reference for JavaScript?

Thanks again!!!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best online reference for javaScript that I know of is Microsoft MSDN. Once the page opens, look at the left frame and select Web Development-->HTML and CSS-->HTML and DHTML Reference. One word of warning: This reference is obviously geared toward Microsoft Internet Explorer, and some of the information given does not apply to javaScript on other browsers.

If you're going to be serious about developing dynamic web pages and writing javaScript, it's worth it to invest in a book, rather than relying on whatever tutorials you can find on the internet. O'Riely's JavaScript The Definitive Guide by David Flanagan has been an indispensable resource for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic