cesarcesar Posted October 22, 2007 Share Posted October 22, 2007 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;" Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 22, 2007 Share Posted October 22, 2007 The "this" in the first code block refers to the input element. If you were to put the button right next to the input field, you could pass this.previousSibling as the element reference http://developer.mozilla.org/en/docs/DOM:element.previousSibling Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted October 22, 2007 Author Share Posted October 22, 2007 emehrkay- i have tried your suggestions. Nothing Happens. the pop up doesn't even pop. Quote Link to comment Share on other sites More sharing options...
nogray Posted October 23, 2007 Share Posted October 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.