unsider Posted August 5, 2008 Share Posted August 5, 2008 I've alowed my users to "preview" the article their creating, check that the WYM editor is functioning properly, but in order to place the article into a category I'm using a <select> form, and the page is refreshed upon previewing the creation, and the select form value is reset. So I'm curious, is it possible to store the selected option in a session value, or would this involve using JS client side to hold the value. Maybe a mixture of both? Thanks. Quote Link to comment Share on other sites More sharing options...
Ace Jon Posted August 5, 2008 Share Posted August 5, 2008 Let's say you're using POST to send the select data to the verification page. What I do is (this is if the 'values' in your <options> are integers, but you could work around that if you're doing something else): $selected = array(); for ($i = 0; $i < $numberofvaluesinselect; $i++) { if ($i == $_POST['selectname']) $selected[$i] = ' selected'; else $selected[$i] = ''; } // Stuff happens, we close PHP with ?> and we're printing the form again: <select name="bla"> <option value="0" <?php echo $selected[0]; ?>>Option 0</option> <option value="1" <?php echo $selected[1]; ?>>Option 1</option> <option value="2" <?php echo $selected[2]; ?>>Option 2</option> <!-- etc --> </select> So, if the value was selected from last time, the <option> of that value says 'selected', otherwise nothing. Quote Link to comment Share on other sites More sharing options...
unsider Posted August 5, 2008 Author Share Posted August 5, 2008 Thanks, worked perfectly. 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.