Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a script from the onClick event of a textbox? 1

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
I have the following snippet of code which shows a little calendar icon and a textbox on the form.

<td width="26" height="24" valign="top"><a href="javascript:show_calendar('form1.datebox');" onMouseOver="window.status='Select a date...';return true;" onMouseOut="window.status='';return true;"><img src="show-calendar.gif" width=24 height=24 border=0></a></td>
<td colspan="2" valign="top"><input name="datebox" type="text" size="10"></td>

Currently, if a user clicks the calendar icon, a calendar pops up and they select a date. The selected date is automatically inserted into the textbox.

In addition to that, I want to force the calendar to appear when the user clicks on the textbox as well. From the reading I've been doing, it seems I need to use either an onFocus event or onClick event but I can't seem to get it to work. Any help or suggestions would be great.
 
Code:
<input name="datebox" type="text" size="10" onfocus="show_calendar(this);" />
How about this?
 
Vragabond-

Thanks for the help... I modified you snippet with the following:

onfocus="show_calendar('form1.datebox');"

This displays the calendar, user selects a date, date is loaded into the textbox. However, after the date is loaded into the textbox, the calendar pops up again. It is acting as if the loading of the date value into the textbox is another onFocus event so it displays the calendar again.

I am looking at the code which inserts the date selected into the textbox to see if that is the issue.
 
Code:
<input name="datebox" type="text" size="10" onfocus="if (this.value == '') show_calendar(this);" />
Maybe like this? Provided there is no value in the box before you start.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top