[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Creating sticky select form field using $_GET[] details.

Probably quite simple but I cant seem to get this working.

I just want the select field to pre-select the $_GET[s_display] value when this is present.

Any help is much appriciated.

*****************************************************************

<select name="s_display">';
   <?php
   $display_number = array (2,5,10,20,30,50,100);
    foreach ($display_number as $key => $value) {
      echo "<option value=\"$key\"";
      if (isset($_GET['s_display']))  {
      echo "selected=\"selected\"";
      }
      echo ">$value</option>\n";
}?>
</select>
0
aegirbrands
Asked:
aegirbrands
1 Solution
 
Joseph MelnickCommented:
Hello aegirbrands,

if you post this then one ove the options will be selected but s_display will be set in ANY case where an ANY option is selected so you must issolate this to maje this work for you. Also if this a form which is POSTed then the $_GET will yield  nothing useful.  


<select name="s_display">
<?php
$display_number = array (2,5,10,20,30,50,100);
foreach ($display_number as $key => $value) {
// lets use request instead of get as I am not sure where the form vars are coming from.
  $s_display = (isset($_REQUEST['s_display']))?$_REQUEST['s_display']:"";
  echo "<option value=\"$key\"";
  if ( $s_display != "" and   $s_display == $value   )  {
    echo " selected=\"selected\"";
  }
  echo ">$value</option>\n";
}

Joseph Melnick
?>
</select>

0
 
aegirbrandsAuthor Commented:
Thank you, just what I needed.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now