• 0

Form


Question

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

  • 0

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

  • 0

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

  • 0

echo "&lt;select name=\"Cat_Salaire_ID\"&gt;";
	while ( $ligne=mysql_fetch_array($result) ){
    if ( $ligne[ID] == $_POST['Cat_Salaire_ID'] ) {
      echo "&lt;option value=" . $ligne[ID] . " selected=true &gt;" . $ligne[Nom] . "&lt;/option&gt;";
    }else{
    echo "&lt;option value=" . $ligne[ID] . "&gt;" . $ligne[Nom] . "&lt;/option&gt;";
  }
	}
	echo "&lt;/select&gt;";

This is what I though of... I'm gonna try it.

Link to comment
Share on other sites

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.