Connecting Tech Pros Worldwide Forums | Help | Site Map

Hidden Values

Newbie
 
Join Date: Mar 2008
Posts: 12
#1: Mar 2 '08
Hi all,

I am new to these forums and decided to join one (this one) after 5 days of researching to try and solve my problem.

I am creating a booking type of calendar. It will be run by an oracle database. From the front end a user will see all the dates that are available (green cells), dates that are pending (orange cells) and dates that are booked (red cells); the user will then click on the dates that are available they want to book, this will turn to yellow, if they change their mind it will turn back to green. This part I am fine with.

The problem I have is with the hidden fields. I would like to change the value of the hidden field from "1, 2" to "1, 2 selected" when the user has clicked on a date. When the page refreshes I would still like the yellow cell to appear and not default back to green. Basically I want to know what dates the user has selected and for the value to go into a database.

I hope I have made sense of what I am trying to do. Any help would be great my code so far is below.

[HTML]<head>
<style type="text/css">
td{width:50px; height:20px; background-color:#009933;}
</style>
<script>
function changeColor(objTD)
{
if(objTD.clicked)
{
objTD.style.backgroundColor = "009933";
objTD.clicked=false;
}
else
{
objTD.style.backgroundColor="FFFF00";
objTD.clicked=true;
}
}

</script>
</head>

<body>
<form name="check" action="">
<table>
<tr>
<td id="r1w1" onClick="changeColor(this)"><input type="hidden" id="r1w1b" name="r1w1" value="1,1"></td>
<td id="r1w2" onClick="changeColor(this)"><input type="hidden" id="r1w2b" name="r1w2" value="1,2"></td>
<td id="r1w3" onClick="changeColor(this)"><input type="hidden" id="r1w3b" name="r1w3" value="1,3"></td>
<td id="r1w4" onClick="changeColor(this)"><input type="hidden" id="r1w4b" name="r1w4" value="1,4"></td>
</tr>
</table>
</form>
</body>[/HTML]

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 2 '08

re: Hidden Values


Quote:

Originally Posted by anonymousstar

I am new to these forums and decided to join one (this one) after 5 days of researching to try and solve my problem.

Welcome to TSDN!

Quote:

Originally Posted by anonymousstar

The problem I have is with the hidden fields. I would like to change the value of the hidden field from "1, 2" to "1, 2 selected" when the user has clicked on a date. When the page refreshes I would still like the yellow cell to appear and not default back to green. Basically I want to know what dates the user has selected and for the value to go into a database.

When you say refresh, do you mean after submitting the form or if the user presses, say, F5?

If it's after submitting, the server-side code should deal with that by adding to the database and showing the correct colour.

If it's after refresh, you'll need cookies to store the information when a cell is clicked on. See this link on cookies.
Newbie
 
Join Date: Mar 2008
Posts: 12
#3: Mar 3 '08

re: Hidden Values


Quote:

Originally Posted by acoder

Welcome to TSDN!

When you say refresh, do you mean after submitting the form or if the user presses, say, F5?

If it's after submitting, the server-side code should deal with that by adding to the database and showing the correct colour.

If it's after refresh, you'll need cookies to store the information when a cell is clicked on. See this link on cookies.

Hiya,

Thank you for your welcome.

The user will need to select a different part of a calendar which will be a new page and not submitted so I think cookies will be the best answer as I assume it will hold the values until he confirms the dates.

What I wanted to know is how to change the value of the hidden field so that I can see what the user has selected. 1,2 is the co-ordinates of the cell. row 1, cell 2 and so on. when they select that cell I would like to concantenate selected onto the 1,2 string. I had this example before but when I went to view the source I did not see a change. Is this because I need to use cookies? The code to change the values is below.

Thank you so much for your help.

Kind regards

anonymousstar

document.getElementByID().value= " + selected";
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Mar 3 '08

re: Hidden Values


Quote:

Originally Posted by anonymousstar

What I wanted to know is how to change the value of the hidden field so that I can see what the user has selected. 1,2 is the co-ordinates of the cell. row 1, cell 2 and so on. when they select that cell I would like to concantenate selected onto the 1,2 string. I had this example before but when I went to view the source I did not see a change. Is this because I need to use cookies?

To concatenate, use += , e.g. document.getElementById("r1w2b").value += " selected".

You won't see a change if you view the source. Inspect the element using, for example, the Firebug extension on Firefox.
Newbie
 
Join Date: Mar 2008
Posts: 12
#5: Mar 3 '08

re: Hidden Values


Quote:

Originally Posted by acoder

To concatenate, use += , e.g. document.getElementById("r1w2b").value += " selected".

You won't see a change if you view the source. Inspect the element using, for example, the Firebug extension on Firefox.


Fantastic
Thank you for your help. It really is appreciated.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Mar 3 '08

re: Hidden Values


You're welcome. Glad it helped.
Reply


Similar JavaScript / Ajax / DHTML bytes