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.

multiple onFocus function & javascript validation question

Hi There

I have a couple of question, which I was hoping someone coudld help me on.

a) I have created a reservation form on a web page and am using JavaScript as my means of validation. On the date fields I want a dialogue box to pop up if the user tries to manually type the date in as I want them to use the date picker I have provided. So I presume I would use the onfocus option available in JavaScript. However I currently already have an onfocus function assigned to that particular field (see below). How can I add an extra onfocus function to this particular form element? Do I simply separate them with a comma?

b) How would I evaluate my txtDateFrom form element against my txtDateTo (same format as the form element displayed above) as I don’t want a user to select a ‘from’ date later then a ‘To’ date and vice versa? Could anyone help me on the best way to actually code this javascript logic using the form element details above?

Firstly, I should warn you... What happens when JavaScript support isn't enabled in the user's browser? You should always validate on the server, even if you validate with JavaScript as well. I am concerned that your code may not be following JavaScript Best Practices. I recommend you read up on them.

a) You can separate multiple function calls with a semi-colon just like in other JavaScript.

I see your point about the client side/server validation, but it is only effectivley a 'request a reservation' process not an actual booking, so I decided to just run with the javascript option.

So how aout this as an option

a) I make the field readonly as suggested
b) then have an onFocus function, which causes a pop-up to appear if the user tries to click into the field.

to do this would I simply have a function for example called 'promptMessage ()' which in the body would simply have an alert(... Then in the form input tag I would promptMessage(); in the onfocus assignment?

I will have the date picker pop up if the user clicks in the text box. I'm having problems actually getting the date picker to appear, is it simply an onfocus function to get the picker to appear? if yes, could someone show me an example of how to call a function like this using a text field?