snrecords Posted November 27, 2007 Share Posted November 27, 2007 Hey again... I have a table where users input a date, time, and quantity for a reservation. On my page ... because I have a junk calendar and coding, every time you click a different month on the calendar or click the "book now" button without entering all the necessary data, the page refreshes and erases all the data. One significant problem is that the times display as radio buttons. Some tours have one time and some have multiple times. On the page, if there is only one time, then to make it easier for users to book tours, I inputted CHECKED into the html code. But unfortunately if the tour has multiple times, then CHECKED doesn't work for the first radio button, it defaults the last radio button because of the php loop. My question is ... how do I always have the first radio button selected as default? Here's the code so far: <?php $times = get_tour_times($tour_id); // var_dump($times); if (isset($times['0'])){ echo '<font color="#5A3D1B" ><span style="margin-left: 22px; font-size:10pt;line-height: 25px; font-family:Palatino Linotype; "><B style="margin-top: 40px;">TIME</B></SPAN></FONT><BR/>'; foreach ($times as $time) { echo('<font color="#5A3D1B" ><span style="margin-left: 5px; line-height: 25px; font-size:10pt; font-family:Palatino Linotype; ">'); echo('<input type="radio" name="tour_time" value="' . $time[1] . '" Checked>'); echo($time[0]); echo("</SPAN></FONT><BR/>"); } }else{ echo '<input type="hidden" name="tour_time_ch" value="--">'; } ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 27, 2007 Share Posted November 27, 2007 why don't you just exclude it from the for loop? just put that specific radio button above the for loop. something like this maybe: <?php $times = get_tour_times($tour_id); // var_dump($times); if (isset($times['0'])){ echo '<font color="#5A3D1B" ><span style="margin-left: 22px; font-size:10pt;line-height: 25px; font-family:Palatino Linotype; "><B style="margin-top: 40px;">TIME</B></SPAN></FONT><BR/>'; echo '<font color="#5A3D1B" ><span style="margin-left: 5px; line-height: 25px; font-size:10pt; font-family:Palatino Linotype; ">'; echo '<input type="radio" name="tour_time" value="' . $time[0] . '" Checked>'; echo "</SPAN></FONT>"; foreach ($times as $time) { echo('<input type="radio" name="tour_time" value="' . $time[1] . '">'); echo($time[0]); echo("</SPAN></FONT><BR/>"); } }else{ echo '<input type="hidden" name="tour_time_ch" value="--">'; } ?> Quote Link to comment Share on other sites More sharing options...
snrecords Posted November 27, 2007 Author Share Posted November 27, 2007 I tried several times using this idea with different codes.... unfortunately it would add an extra radio button that doesn't input the correct time into the session... any other ideas..? Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 So many people forget about simple for loops this code takes a arg called "tour" if it is not there it defaults to 5 times <?php ob_start(); session_start(); function get_tour_times($tour_id){ switch ($tour_id) { case 1: $temparray = array('08:00'); return $temparray; break; case 2: $temparray = array('08:00','10:00'); return $temparray; break; case 3: $temparray = array('08:00','10:00','13:00'); return $temparray; break; case 4: $temparray = array('08:00','10:00','13:00','15:00'); return $temparray; break; default: $temparray = array('08:00','10:00','13:00','15:00','18:00'); return $temparray; break; } } if (isset($_REQUEST['tour'])) { $tour_id = $_REQUEST['tour']; } else { $tour_id = 0; } $times = get_tour_times($tour_id); // var_dump($times); if (isset($times['0'])){ echo '<font color="#5A3D1B" ><span style="margin-left: 22px; font-size:10pt;line-height: 25px; font-family:Palatino Linotype; "><B style="margin-top: 40px;">TIME</B></SPAN></FONT><BR/>'; for ($i=0;$i < count($times);$i += 1) { $checkval = ($i == 0)?'checked':''; echo('<font color="#5A3D1B" ><span style="margin-left: 5px; line-height: 25px; font-size:10pt; font-family:Palatino Linotype; ">'); echo '<input type="radio" name="tour_time" value="' . $times[$i] . '" '.$checkval.'>'; echo($times[$i]); echo("</SPAN></FONT><BR/>"); } }else{ echo '<input type="hidden" name="tour_time_ch" value="--">'; } ?> 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.