Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
correct array reference syntax
Old 10-21-2007, 09:17 PM correct array reference syntax
Extreme Talker

Posts: 196
Trades: 0
I am using a js calendar script that populates a text field with a date. When clicking in the field the calendar shows then i choose a date, calendar closes, the date is now in the field. great it works fine.

example- *note, array use[]*
Code:
<input type="text" id="example[]" name="example[]" value="" onfocus="if(self.gfPop)gfPop.fPopCalendar(this);return false;">
I want to make this call from a button. when adding the code to a href, the popup shows but nothing happens when selecting a date. I have tried the following scripts will failure.

*html a href and img tag left out*
Code:
onclick="if(self.gfPop)gfPop.fPopCalendar(document.this_form.elements['example[]']);return false;"

onclick="if(self.gfPop)gfPop.fPopCalendar(document.this_form.example[]);return false;"

onclick="if(self.gfPop)gfPop.fPopCalendar(this);return false;"
empiresolutions is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-01-2007, 09:43 PM Re: correct array reference syntax
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Try this:

Code:
onclick="if(self.gfPop)gfPop.fPopCalendar(document.this_form['example[]']);return false;"
Your second example was almost right. In JS you can access properties via the "dot" notation, or array notation. But since you have special characters (the []'s) in your field name, you are forced to use the array notation. That is, these two are the same:

Code:
myvar = someobj.prop;
// and
myvar = someobj['prop'];
But in the case where 'prop' has special characters, there is only one way:
Code:
myvar = someobj.prop!;// wont work
myvar = someobj['prop!']; // will work
Your first try could be correct if you knew the field index. form.elements[] is a numeric array with indexing starting at 0 which equals the first element in the form.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to correct array reference syntax
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10009 seconds with 12 queries