Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > javascript variables...

javascript variables...
Thread Tools
macfan_1280
Fresh-Faced Recruit
Join Date: Feb 2006
Status: Offline
Reply With Quote
Feb 2, 2006, 12:24 PM
 
Hi,

First, I should mention that I'm not too familiar with Javascript. I can get basic tasks done, but don't have much experience.

I was recently asked to make some modifications to a web page that uses javascript for validation. One of the form's fields is:
<type="hidden" name=" _mygroup.TEXTAREA.myItem" value="test 1106 feb 2">

so, how could I retrive the value of the field. It seems like the periods are confusing the javascript engine.

Here's what I'm trying to do on a submit:
alert("item="+ document.forms(0)._mygroup.TEXTAREA.myItem.value );
...it keeps telling me that something is not an object....I think it's seeing the periods inside the item's name and is thus looking for its information.


Thank you in advance for any help.
     
madmacgames
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Feb 2, 2006, 05:32 PM
 
When you have a name of something like that which uses characters that javascript will interpret differently, put it in square braces and quote it so that javascript does not interpret the special characters as literals, but instead uses them in the object's name:
Code:
document.forms(0)['_mygroup.TEXTAREA.myItem'].value
You can do the same with the form name as well:
Code:
document.forms['myFormName']['_mygroup.TEXTAREA.myItem'].value
And also call the form "normally" if it doesn't have a funny name:
Code:
document.forms.myFormName['_mygroup.TEXTAREA.myItem'].value
The only thing necessary for evil to flourish is for good men to do nothing
- Edmund Burke
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:51 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,