Javascript + HTML form + dates + PHP
Posted: Wed Mar 19, 2008 6:25 am
Hello all!
Here's hoping someone here can help me out; Javascript has never been a strong point of mine although I think the problem I have should be fairly easy to solve...
I'm working on a library/book system for work - people come in and borrow books, yadda yadda... all simple stuff. When they borrow a book the Due Date is automatically created as 7 days after todays date, although since it's in an HTML form it can easily be changed by the person entering the loan info.
However, the user is allowed to renew the book twice... which is where my query comes in :-
On the Edit Loan form, the data is populated from a MySQL database. The Due Date is displayed in an <input type="text"> form field, but I have a button next to it which says 'Renew Item'. I want to be able to click the button, and some whizzy Javascript (some sort of onClick event I suppose) checks the DueDate in the form field, adds 7 days to it, and re-displays the new DueDate.
Also, since I need to check if an item has been renewed before (with a max number of 2 times), I have 2 hidden fields on the form called RenewDate_1 and RenewDate_2 - so I need to check whether they have values other than '0000-00-00' - if not then add todays date to either RenewDate_1 or RenewDate_2 as appropriate.
Checking values with MySQL/PHP is no problem, but checking the form values with Javascript and updating form fields I have no clue about! The onClick to change the date I'm sure should be basic stuff, but I've searched t'internet and can't find anything. Checking hidden form fields then changing them is probably a bit more complicated, but should be do-able without too much hassle... I hope!
Thanks in advance.
Here's hoping someone here can help me out; Javascript has never been a strong point of mine although I think the problem I have should be fairly easy to solve...
I'm working on a library/book system for work - people come in and borrow books, yadda yadda... all simple stuff. When they borrow a book the Due Date is automatically created as 7 days after todays date, although since it's in an HTML form it can easily be changed by the person entering the loan info.
However, the user is allowed to renew the book twice... which is where my query comes in :-
On the Edit Loan form, the data is populated from a MySQL database. The Due Date is displayed in an <input type="text"> form field, but I have a button next to it which says 'Renew Item'. I want to be able to click the button, and some whizzy Javascript (some sort of onClick event I suppose) checks the DueDate in the form field, adds 7 days to it, and re-displays the new DueDate.
Also, since I need to check if an item has been renewed before (with a max number of 2 times), I have 2 hidden fields on the form called RenewDate_1 and RenewDate_2 - so I need to check whether they have values other than '0000-00-00' - if not then add todays date to either RenewDate_1 or RenewDate_2 as appropriate.
Checking values with MySQL/PHP is no problem, but checking the form values with Javascript and updating form fields I have no clue about! The onClick to change the date I'm sure should be basic stuff, but I've searched t'internet and can't find anything. Checking hidden form fields then changing them is probably a bit more complicated, but should be do-able without too much hassle... I hope!
Thanks in advance.