Scorptique Posted November 13, 2008 Share Posted November 13, 2008 This is a drop down menu of day / month / year. I dont know how to make it sticky since it's already in a php tag. Does anyone know how to make it sticky? Help please! Sticky means that when user refreshes the page, the value in the form will still remain the same. <?php echo "<select name='day'>"; for ($x=1; $x<=31; $x++) { echo "<option value=$x>$x</option>"; } echo "</select> "; echo "<select name='month'>"; for ($x=1; $x<=12; $x++) { echo "<option value=$x>$x</option>"; } echo "</select> "; echo "<select name='year'>"; for ($x=2008; $x>=1930; $x--) { echo "<option value=$x> $x </option>";} echo "</select> "; ?> Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/ Share on other sites More sharing options...
premiso Posted November 13, 2008 Share Posted November 13, 2008 What do you mean by "make it sticky" ? Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689324 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 You have to encapsulate your code in glue tags, obviously. Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689328 Share on other sites More sharing options...
Maq Posted November 13, 2008 Share Posted November 13, 2008 You have to encapsulate your code in glue tags, obviously. Still may fall off the screen, better use crazy glue. Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689423 Share on other sites More sharing options...
Maq Posted November 13, 2008 Share Posted November 13, 2008 Just like how you pass values to another page, pass it to itself. Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689425 Share on other sites More sharing options...
Goldeneye Posted November 13, 2008 Share Posted November 13, 2008 Assuming you're talking about what I think you're talking about (retaining form values upon page-reload), use: <?php echo "<select name='year' value='".$_POST['year']."'>"; //I just assumed your form method was POST, use $_GET otherwise (obviously) for ($x=2008; $x>=1930; $x--) { echo "<option value=$x> $x </option>";} echo "</select> "; ?> Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689435 Share on other sites More sharing options...
flyhoney Posted November 13, 2008 Share Posted November 13, 2008 Firefox has a little proprietary piece of annoyance called autocomplete that remembers select box values, usually I am fighting to turn if off: <form autocomplete="off"> </form> Try this: <?php echo '<select name="day">'; for ($x=1; $x<=31; $x++) { echo '<option value="'.$x.'" '.($_POST['day'] == $x) ? 'selected="selected"' ? ''.'>'.$x.'</option>'; } echo '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-689459 Share on other sites More sharing options...
Scorptique Posted November 21, 2008 Author Share Posted November 21, 2008 Flyhoney, I dont understand why are the question marks in it. What does it mean? I copied this sentence to my code and there was some ';' error =/ echo '<option value="'.$x.'" '.($_POST['day'] == $x) ? 'selected="selected"' ? ''.'>'.$x.'</option>'; Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-695526 Share on other sites More sharing options...
.josh Posted November 21, 2008 Share Posted November 21, 2008 change the 2nd ? to a : It's called a ternary operator. Basically it's a shorthand version of an if..else. if(condition) { // condition is true } else { // condition is false } vs. (condition) ? 'condition is true' : 'condition is false' example: $x = 5; echo ($x < 10)? 'x is less than 10' : 'x is greater than 10'; that would echo 'x is less than 10' Link to comment https://forums.phpfreaks.com/topic/132566-sticky-form-but-already-in-php-tags-help/#findComment-695529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.