Get text of select box in php page -


i have select box in php , want text selected item of that:

<form action="" method="get" target="" dir="rtl" class="w3-container">   <?php    echo " <select id='p1' name='p1'  >";  echo "<option  value='*'>choose person</option>"; sql code   $result2 = mysql_query($query2,$con);  while($row2 = mysql_fetch_array($result2))  { $row2['name']; echo "<option  value='".$row2['id']."'>".$row2['name']."</option>";  } echo " </select>";  mysql_close($con);  ?>  <input  class="w3-btn w3-hover-yellow" name="" type="submit" value="جستجو"> </form>  <?php if(isset($_get['p1']) , $_get['p1'] != "*") {       if ($name_insert=trim($_get["p1"])) {             if ($strwhere == ""){         $strwhere .= "name_insert='".trim($name_insert)."' ";         $getpage .= "&name_insert=".($name_insert);}         else{         $strwhere .= " , name_insert='".trim($name_insert)."' ";         $getpage .= "&name_insert=".($name_insert);}     } } ?> 

i want code text of select box in $name_insert. code gets value of that.

you can use javascript , save selected option text in hidden field.

example

<form  action=""  method="post">       <select id="test" onchange="document.getelementbyid('text_content').value=this.options[this.selectedindex].text">      <option value="1">test one</option>      <option value="2">test two</option>     </select>  <input type="hidden" name="test_text" id="text_content" value="" /> </form> 

php

$getoptiontext = $_post['test_text']; 

replace code code

<form action="" method="get" target="" dir="rtl" class="w3-container">   <select id='p1' name='p1'  onchange="document.getelementbyid('text_content').value=this.options[this.selectedindex].text">  <option  value='*'>choose person</option> <?php  $result2 = mysql_query($query2,$con);  while($row2 = mysql_fetch_array($result2))  {  echo "<option  value='".$row2['id']."'>".$row2['name']."</option>";  } mysql_close($con);  ?> </select>  <input type="hidden" name="test_text" id="text_content" value="" />  <input  class="w3-btn w3-hover-yellow" name="" type="submit" value="جستجو"> </form>  <?php if(isset($_get['p1']) , $_get['p1'] != "*") {    $getvalueoftext =  $_get['test_text'];    echo $getvalueoftext;      if ($name_insert=trim($_get["p1"])) {             if ($strwhere == ""){         $strwhere .= "name_insert='".trim($name_insert)."' ";         $getpage .= "&name_insert=".($name_insert);}         else{         $strwhere .= " , name_insert='".trim($name_insert)."' ";         $getpage .= "&name_insert=".($name_insert);}     } }  ?> 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -