Jump to content

correct array reference syntax


cesarcesar

Recommended Posts

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[]*

<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*

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;"

Link to comment
Share on other sites

The problem is that you're trying to access the object which has ([]) in the name. This make it an array and hard to access using JS by calling the name.

 

Since the ID is only used in the front end (the name will be using in the backend script like PHP), you can change the ID to example_1 and using document.getElementById('example_1') on the onclick event.

 

This way, you are sure that the object is passed to the calendar.

 

You might also try the NoGray calendar at http://www.nogray.com/calendar.php

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.