Nodiaque Posted April 21, 2003 Share Posted April 21, 2003 Hi, I have an html form that use an option box. Now, I wish to set a default value in it according to the value in param (php, $_POST var). How can I do that? Thanks Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted April 21, 2003 Veteran Share Posted April 21, 2003 <input ..... value="<?= $_POST['variable_name'] ?>" /> :) Link to comment Share on other sites More sharing options...
0 Quboid Posted April 21, 2003 Share Posted April 21, 2003 I've heard that come PHP5, the quick tags like Timdorr uses above will be scrapped (due to compatibility problems with XHTML, and probably other reasons), so if you want to ensure the script will continue to work, do this: <input ..... value="<?php print $_POST['variable_name']; ?>" /> Simple. Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted April 21, 2003 Veteran Share Posted April 21, 2003 oh wow, that sucks... :/ (/me goes off to recode some stuff ;) ) Link to comment Share on other sites More sharing options...
0 Nodiaque Posted April 21, 2003 Author Share Posted April 21, 2003 well, i use echo $_post anyway Link to comment Share on other sites More sharing options...
0 Nodiaque Posted April 22, 2003 Author Share Posted April 22, 2003 And, btw, the code you gave me doesn't select the value from the drop box but put a selected value into the drop box. What I want is that the last selected value stay selected... Link to comment Share on other sites More sharing options...
0 Nodiaque Posted April 22, 2003 Author Share Posted April 22, 2003 echo "<select name=\"Cat_Salaire_ID\">"; while ( $ligne=mysql_fetch_array($result) ){ if ( $ligne[ID] == $_POST['Cat_Salaire_ID'] ) { echo "<option value=" . $ligne[ID] . " selected=true >" . $ligne[Nom] . "</option>"; }else{ echo "<option value=" . $ligne[ID] . ">" . $ligne[Nom] . "</option>"; } } echo "</select>"; This is what I though of... I'm gonna try it. Link to comment Share on other sites More sharing options...
0 Quboid Posted April 22, 2003 Share Posted April 22, 2003 We were talking about an input box, not a drop down menu, sorry. For a DDM, what you have is good, except the instead of selected=true, I'd put selected=\"selected\", which I think is the correct HTML, with the value correctly put in quote marks. Link to comment Share on other sites More sharing options...
0 Nodiaque Posted April 22, 2003 Author Share Posted April 22, 2003 well, it worked with true... because the field selected is a boolean field, so any value other then false would work, I think Link to comment Share on other sites More sharing options...
Question
Nodiaque
Hi, I have an html form that use an option box. Now, I wish to set a default value in it according to the value in param (php, $_POST var). How can I do that?
Thanks
Link to comment
Share on other sites
8 answers to this question
Recommended Posts