chuflasky Posted May 7, 2012 Share Posted May 7, 2012 Hi, i created a function for a pull down selection date just like in script 3.7 but where in the code do i should put the code to make it sticky, i already tried function event_date($value,$day, $year){ /*echo'<script type="text/javascript" src="../js/jQuery_v1.4.4.js"> </script>'; echo'<script type="text/javascript" src="../js/upload_js.js"></script>'; */ //make the month // $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December'); echo '<select name="event_month" id="a_place" value=\"<?php if (isset($_POST['event_month'])) echo $_POST['event_month'];\" >'; echo'<option value="0">Month</option>'; foreach($month as $key =>$value){ echo "<option value=\"$key\">$value</option>"; } if($_POST["event_month"] == "$value"){ echo 'selected = "selected" '; } if(isset($value)) echo "$value"; echo '</select>'; // make the days echo '<select name=\"event_day\" id=\"a_place\" >'; echo '<option value="0">Day</option>'; for($day=1; $day<=31; $day++){ echo "<option value=\"$day\">$day </option>"; } if($_POST["event_day"] == "$day"){ echo 'selected = "selected" '; }else if( $month==2){ for( $day=1; $day<=29; $day++){ echo "<option value=\"$day\">$day</option>"; }//end of for loop }// end of elseif if(isset($_POST['event_day']) ) echo $_POST['event_day']; echo '</select>'; //make the year echo '<select name="event_year" id="a_place">'; echo '<option value="0">Year</option>'; for($year = 2011; $year<=2020; $year++){ echo "<option value=\"$year\">$year</option>"; } if($_POST["event_year"] == "$year"){ echo 'selected = "selected" '; } echo '</select>'; return TRUE; }//end of event_date function and it not working for me. Thanks Link to comment Share on other sites More sharing options...
Larry Posted May 7, 2012 Share Posted May 7, 2012 HOW is it not working for you? What doesn't happen that should? What does happen that shouldn't? What debugging steps have you taken and what were the results? Link to comment Share on other sites More sharing options...
Edward Posted May 7, 2012 Share Posted May 7, 2012 I have some code i made up for this review and pursue, This was in the HTML <form> tag to make a sticky drop down menu, it was regarding a parcel and how it should be taken care of, the options you could select were "Don't worry about my parcel" or "Be careful with my parcel". I know its a bit lame but it worked out for me. <p>Parcel Care: <select name="parcel"> <option value="noworry" <?php if (isset($_POST['parcel']) && ($_POST['parcel'] == 'noworry')) echo ' selected="selected"'; ?>>Don't worry about my parcel</option> <option value="becareful" <?php if (isset($_POST['parcel']) && ($_POST['parcel'] == 'becareful')) echo ' selected="selected"'; ?>>Be careful with my parcel</option> </select></p> Link to comment Share on other sites More sharing options...
chuflasky Posted May 7, 2012 Author Share Posted May 7, 2012 Thanks Larry / Edward for your quick respond, Well i tried to put the sticky code at the at the <select> input to make sticky but for some reason after i submit the form it hold no value. Here is how i'm making my input to make it sticky echo '<select name="event_month" id="a_place" value=\"<?php if(isset($_POST['event_month'])) echo $_POST['event_month'];?>\">'; everything else is working find but just the sticky part. Link to comment Share on other sites More sharing options...
Larry Posted May 7, 2012 Share Posted May 7, 2012 That won't work at all. Select tags don't have value attributes. To make a select element sticky, you need to add the selected="selected" to the correct option element. Link to comment Share on other sites More sharing options...
Edward Posted May 7, 2012 Share Posted May 7, 2012 I've just written the code for a month's stick select menu: <h1>Month's Select Form</h1> <form action="selectmenu.php" method="post"> <p>Select Menu: <select name="month"> <?php $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); foreach($month as $key =>$value) { echo "<option value=\"$value\""; if (isset($_POST['month']) && ($_POST['month'] == $value)) { echo ' selected="selected"'; } echo ">$value</option>"; } ?> </select></p> <input type="submit" name="submit" value="Check if date is sticky??" /> </form> 1 Link to comment Share on other sites More sharing options...
Edward Posted May 7, 2012 Share Posted May 7, 2012 I haven't coded that kind of stuff for about a month now, it took me about 30 minutes to do that, i tripped up on a few things, my original script was like this: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['distance'], $_POST['courier'], $_POST['parcel'], $_POST['delivery_notes']) && is_numeric($_POST['distance']) && (isset($_POST['commercial']) || isset($_POST['gift']) || isset($_POST['education']) || isset($_POST['business']))) { echo '<h2>Form Complete</h2>'; echo "<p>Thank You for Picking " . $_POST['courier'] . "</p>"; if(isset($_POST['education'])) echo "<p>Your parcel will be sent for Education </p>"; echo "<p>We " . $_POST['parcel'] . " about your parcel</p>"; echo "<p>Your delivery notes are " . $_POST['delivery_notes'] . "</p>"; } } ?> <form action="shipping.php" method="post"> <h1>Please fill out the delivery form</h1> <p>Estimated distance in miles: <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>" /></p> <p>Select a shipping company: <input type="radio" name="courier" value="Standard Mail" <?php if (isset($_POST['courier']) && ($_POST['courier'] == 'Standard Mail')) echo 'checked="checked" '; ?> /> Standard Mail <input type="radio" name="courier" value="EMS" <?php if (isset($_POST['courier']) && ($_POST['courier'] == 'EMS')) echo 'checked="checked" '; ?>/> EMS <input type="radio" name="courier" value="DHL" <?php if (isset($_POST['courier']) && ($_POST['courier'] == 'DHL')) echo 'checked="checked" '; ?>/> DHL </p> <p>What type of parcel is it? <input type="checkbox" name="commercial" value="commercial" <?php if (isset($_POST['commercial'])) echo 'checked="checked"'; ?> />Commercial <input type="checkbox" name="gift" value="gift" <?php if (isset($_POST['gift'])) echo 'checked="checked"'; ?>/>Gift <input type="checkbox" name="education" value="education" <?php if (isset($_POST['education'])) echo 'checked="checked"'; ?>/>Education <input type="checkbox" name="business" value="business" <?php if (isset($_POST['business'])) echo 'checked="checked"'; ?>/>Business </p> <p>Parcel Care: <select name="parcel"> <option value="noworry" <?php if (isset($_POST['parcel']) && ($_POST['parcel'] == 'noworry')) echo ' selected="selected"'; ?>>Don't worry about my parcel</option> <option value="becareful" <?php if (isset($_POST['parcel']) && ($_POST['parcel'] == 'becareful')) echo ' selected="selected"'; ?>>Be careful with my parcel</option> </select></p> <p>Delivery Notes: <textarea name="delivery_notes" rows="3" cols="40"><?php if (isset($_POST['delivery_notes'])) echo $_POST['delivery_notes']; ?></textarea> </p> <p> <input type="submit" name="submit" value="Check Delivery Details" /> </p> </form> I didn't cover all options to be printed out but i could of made a case statement or so if I wanted to, i was just practicing with some of the stuff we done, that's all. Link to comment Share on other sites More sharing options...
chuflasky Posted May 8, 2012 Author Share Posted May 8, 2012 Thanks guys for you help is working fine now my problem was that i was closing the condition before the <option> for example $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December'); echo '<select name="event_month" id="a_place" >'; echo'<option value="0">Month</option>'; foreach($month as $key =>$value){ echo "<option value=\"$value\">$value</option> } if($_POST['event_month']) =="$value"){ echo 'selected="selected" '; } echo"</selected>"; and the correct way that actually works is $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December'); //make the month pulldown menu echo '<select name="expire_month" id="expire">'; echo"<option value='0'>Exp-Month</option>"; foreach($month as $key => $value){ echo "<option value=\"$value\" "; if($_POST["expire_month"] == "$value"){ echo 'selected ="selected" '; } echo"> $value</option>"; } //end of foreach echo '</select>'; as you can see the all of the argument are inside the foreach loop that was the difference. Thanks Edward looking at your code i figure it out. The same code work for the day and year. echo '<select name="expire_day" id="expire">'; echo"<option value='0'>Exp-Day</option>"; for($day= 1; $day<=31; $day++){ echo "<option value=\"$day\" "; if($_POST["expire_day"] == "$day"){ echo 'selected = "selected" '; } echo ">$day</option>\n"; } echo '</select>'; and year echo '<select name="expire_year" id="expire">'; echo"<option value='0'>exp-Year</option>"; for($year = 2011; $year<=2016; $year++){ echo "<option value=\"$year\" "; if($_POST["expire_year"] == "$year"){ echo 'selected = "selected" ' ; } echo " >$year</option>" ; } echo '</select>'; Thanks guys. Link to comment Share on other sites More sharing options...
chuflasky Posted May 8, 2012 Author Share Posted May 8, 2012 Now i have a interesting question. How can change the days to 29 if february is chosen on the event_day selection?. Link to comment Share on other sites More sharing options...
Edward Posted May 8, 2012 Share Posted May 8, 2012 Use the following PHP function in the link to calculate the number of days for a given date. http://php.net/manua...ys-in-month.php If you have other related problem alike this, its worth checking through the PHP's function's on www.php.net, PHP has function's which answer most of our questions. But if you are using a form of SQL, MySQL for example, SQL has its own list of functions, so you can do your calculations before PHP even receives the data from the SQL query. 2 Link to comment Share on other sites More sharing options...
chuflasky Posted May 8, 2012 Author Share Posted May 8, 2012 Thanks Edward, you been very helpful, i will keep it in mind. 1 Link to comment Share on other sites More sharing options...
Recommended Posts