aspose file tools*
The moose likes Struts and the fly likes Accessing indexed properties in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing indexed properties in Javascript" Watch "Accessing indexed properties in Javascript" New topic
Author

Accessing indexed properties in Javascript

Charanjit Sidhu
Greenhorn

Joined: Apr 04, 2005
Posts: 13
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!


Charanjit Sidhu<br />SCJP 81%
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
Charanjit Sidhu
Greenhorn

Joined: Apr 04, 2005
Posts: 13
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

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing indexed properties in Javascript