<select name="ReaderType" style="width: 300px;">
	<option value="0" selected>In/Out</option>
	<option value="1" >Non In/Out</option>
</select>

Causing Form To Submit OnChange

 <select name="my_playlists" id="my_playlists" onchange="this.form.submit()">

Loading With Selected Setting From PHP – Using an array

	$MySelectBoxSelected = array();
	$MySelectBoxSelected = array_fill(0, 20, "");		//Fill an array from index 0, 20 items long, with default value ""
	$MySelectBoxSelected[($TheCurrentSetting)] = "selected ";

  $MySelectBox_html = <<<_END
  <select name="my_select_box" style="width: 200px;">
    <option value="0" $MySelectBoxSelected[0]>My Option 0</option>
    <option value="1" $MySelectBoxSelected[1]>My Option 1</option>
    <option value="2" $MySelectBoxSelected[2]>My Option 4</option>
    <option value="3" $MySelectBoxSelected[3]>My Option 3</option>
  </select>
_END;

Loading With Selected Setting From PHP – Using find and replace on a string

  //----- APPLY SELECTED STATUS TO ALREADY KNOWN SELECT BOXES -----
  //$HtmlOutput   String already containing the HTML with the select control in it
  //               None of the <option> elements have been set to selected
  $data = "the_selected_value";   //<<<If it matches <option value="the_selected_value">blah...</option> then "selected" will be added 
  if (!empty($data))
  {
    //Change this:
    //  <option value="something">Something</option>
    //To this:
    //  <option selected value="something">Something</option>
    $SearchString = 'value="' . $data . '"';
    $ReplaceString = 'selected value="' . $data . '"';
    $HtmlOutput = str_replace($SearchString, $ReplaceString, $HtmlOutput);
  }

Doing specific things

Get selected item text
  <select id="SelectCategory" name="SelectCategory" style="width:100%; max-width:400px" onchange="javascript:PopulateCategoryType();" >
    ...
  </select>

  <script>
    function PopulateCategoryType() {
      var e = document.getElementById('SelectCategory');
      var result = e.options[e.selectedIndex].text;
      document.getElementById('ResourceCategoryType').value = result;
    }
    setTimeout(PopulateCategoryType(), 2500);
  </script>
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *