The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

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.

concatenating javascript string

hello - I am trying to simplify a date picking function for a calendar application I am building. I have a form that gets submitted to a database and previously I was making users type the date of the program they were entering using a format that the database could use (YYYY-MM-DD).

I thought I could make things easier on them, if not me, by using pulldowns for the date elements. The idea would be that they could pick the year, the month, and the day off the pulldowns and I'd have some javascript that would bring it together and format the date in YYY-MM-DD format.

So, what I have come up with is as follows. When they select the day, it calls the checkdate() function. In this function:

I can get it so it writes the year in there, but even then, that only works when they first make selections of the other two. This is not so much a problem, as the larger problem of being able to make window.document.content_ui.scheduled.value = year_select - month_select - day_select;

I just want to make the 'scheduled' input box have something like 2001-12-29. So I have to somehow string the values of year_select month_select and day_select together with hyphens in between.

Anyone know how to do this? General susggestions on how to improve the code also very, very welcome. Thanks.

you only need to specify a window if you are dealing with more than one frame or a popup. You do not need to specify the selectedIndex as a separate var; if you feel you must, re-use the var; don't create one for each selection list.

finally you should 'lock' the text box in the following manner:

<input type='text' name='scheduled' onFocus='this.blur()'>

that will prevent the user from changing the value once you fill it with your function.