php - Display selected option on same page after reload page -


i have select option when select items after click on button page reload on same page. want to selected option after reload page also. here php script

<select id="poet_id" class="filter-btn txtentry2"> <option value="">-poet- </option> <?php foreach ($poet_list $poet){ ?>     <option selected="selected" value="<?php  echo $poet["pi"]; ?>"><?php if($poet["pe"]){ echo $poet["pe"]; } elseif($poet["ph"]){ echo $poet["ph"]; }else{ echo $poet["pu"];} ?></option> <?php } ?> </select> 

here jquery script

$(function() {   $("#video_search").click(function() {     var poet_id = $("#poet_id").val(); //alert(poet_id);         var singer_id = $("#singer_id").val(); //alert(singer_id);      if (singer_id == "" && poet_id == "") {       //alert('please select singer name');       $("#response").html("please select singer or poet name").show().fadeout(3000).css("color", "red");     } else {       //var info='type='+ type_id +'&category=' + category;       var info = 'singer_id=' + singer_id; {         if (info) {           //alert(info);           window.location.href = "videos.php?singer_id=" + singer_id + '&poet=' + poet_id;         } else {           alert('no data found');         }        }     }   }); }); 

i using script failed display selected option on page. thanks

you setting selected on options. make conditional value of $poet["pi"] matching value of $_get['poet'].

something like:

<?php  $poetid = isset($_get['poet']) ? $_get['poet'] : false; foreach ($poet_list $poet){    $selected = '';   if($poetid && $poetid === $poet["pi"]){       $selected = 'selected="selected";   }  ?>     <option <?php echo $selected;?> value="<?php  echo $poet["pi"]; ?>"><?php if($poet["pe"]){ echo $poet["pe"]; } elseif($poet["ph"]){ echo $poet["ph"]; }else{ echo $poet["pu"];} ?></option> <?php } ?> 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -