I know its a cliche, but I am a newbie when it comes to javascript. So any help is greatly appreciated.
I am trying to use javascript for the following :-
- Using OnClick, swap the bgcolor of a cell, depending on the existing bgcolor, eg. turns Blue when click if the current bgcolor is Red and vice versa
- Be able to swap multiple cells before clicking on a Submit/Update button
- Post values of those cells that have been change into an array in the HTML Form, eg. "YYYYMMDD*Yes" for Blue and "YYYYMMDD*No" for Red
The code below works in changing the bgcolour, but will not retain any changes done if I click on another cells.
To summarised, the default colour of each cell is retrieved from a MySQL table. Admin will then be able to change the availability status of each day (multiple selection) by clicking on the cells. Once all changes have been made, clicking on the SUBMIT button will update the MySQL table with the changes made. Default value would be Blue (Yes or Available).Code:var whosChanged = null; function changeColor(el) { el.style.backgroundColor = "#dc143c"; if (whosChanged != null) { whosChanged.style.backgroundColor = "#2e8b57" } whosChanged = el; }
I know this could easily be done by using checkbox, but using color swap would be great and looks better.
Thanks in advance for any help given.



Reply With Quote
Bookmarks