Drainy Posted February 7, 2009 Share Posted February 7, 2009 Hi, A while ago I posted on here for some help with a calender/booking system I was developing. I have now hit another wall! So far I have successfully implemented it automatically generating the calender accurately, assigning an ID to each cell which identifies it by the month and day number, eg february3 is the 3rd of feb. Using javascript and forms I have created a way to save a 1 or a 0 when a cell is selected. So if a user wanted to book 5 days in feb they can click on the cells for february 5,6,7,8,9 and the javascript assigns a value of 1 to each ID (february5, february6 etc). All other values which arent selected are automatically assigned a 0. When I pass this through to the next php script to confirm bookings I hit a wall. The only way I can see of verifying which variables have had a 1 set is to do an if for every single possible variable, so I would have to type in every single month and day combination. I am certain there must be an easier way for me to go about this but I can think of one or find one in any functions ive looked at. Does anyone know of a function or could prod me in the right direction so I can create a solution to this? Quote Link to comment Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 How about instead of making the value 1 or 0, you make it 'id' or 0? Quote Link to comment Share on other sites More sharing options...
Drainy Posted February 7, 2009 Author Share Posted February 7, 2009 Even if I was to do that how could I access the post data that only has an id? Quote Link to comment Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 It depends on how you have your form setup. In order for values to be passed to the server, you have to name the element with the name attribute. The server doesn't care about the id attribute; that's a clientside thing. If your cells are not form elements, you will need to use javascript to grab the id of the flagged cells and put it in a variable (array would be better, since you're wanting to have multiple values) that can be posted. You'd have to use for instance onsubmit and call a function or something. I can't really be more specific than that without seeing actual code. Quote Link to comment Share on other sites More sharing options...
Drainy Posted February 7, 2009 Author Share Posted February 7, 2009 <input type='hidden' name='$titlelower$daynum' id='$titlelower$daynum' value='0'><td align=center bgcolor=#000000 onClick=\"booking('$titlelower$daynum');tabClick(event)\">$daynum</td> Each TD is defined as above. the onclick booking is what assigns a value of 1 or 0, dependant on if 1 or 0 is already set (it toggles between them). The tabclick event is simply to change the cell colour so the user can identify visually what they have selected. As this is inside of a PHP script the name of each form element is based on the month and day number. I just then submit this to another script, at the moment all this does is display the entire contents of the POST vars just so I could verify that it is correctly selecting and de-selecting data and then passing it over. So at the moment if I was to select the 1st, 3rd, 4th and 7th and then submit my verification page displays the following; Array ( [february1] => 1 [february2] => 0 [february3] => 1 [february4] => 1 [february5] => 0 [february6] => 0 [february7] => 1 [february8] => 0 [february9] => 0 [february10] => 0 [february11] => 0 [february12] => 0 [february13] => 0 [february14] => 0 [february15] => 0 [february16] => 0 [february17] => 0 [february18] => 0 [february19] => 0 [february20] => 0 [february21] => 0 [february22] => 0 [february23] => 0 [february24] => 0 [february25] => 0 [february26] => 0 [february27] => 0 [february28] => 0 [submit] => submit ) Does that help clarify what im doing? Quote Link to comment Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 Okay so you have a hidden field for every single day of the month. How about instead of having your onsubmit toggle the value, you have it create/destroy the field? That way, only the ones that are 'highlighted' will have hidden fields, and only those will be sent? Quote Link to comment Share on other sites More sharing options...
Drainy Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks for that, its given me some ideas and its made me shoot off and try and create a function for that. Its crashing and burning at the moment though, JavaScript isnt a strong point of mine so ive had to try and craft it from what I am reading at the moment. Can you help with javascript or am I best off posting in the JavaScript forum? Just for refence if you can help; function booking(id) { var currentDay = document.getElementById(id); if (document.getElementById(id).value == null) { var newNode = "<input type='hidden' name='" + id + "' id='" + id + "' value='1'>"; var parent = document.getElementById("content"); parent.insertBefore(newNode,document.getElementById(id)); } else { currentDay.parentNode.removeChild(currentDay); } } That is what I believe should create or destroy but its not working at all at the moment, I am having a hard time getting my head around what some parts of this are doing. Quote Link to comment Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 I'm not an expert at JavaScript either, but I'll look at it. In the mean time, I'll move it to the js forum. Maybe someone will know right off the bat, there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.