0

I want to print the selected item value of a drop down list in html by using php.

This is what I was trying to do. Year Year I Sem I Year I Sem II Year II Sem I Year II Sem II Year III Sem I Year III Sem II Year IV Sem I Year IV Sem II

    echo $semester ;

?>`

Any help is highly appreciated.Thanks in advance.

VOSH
  • 123
  • 9

2 Answers2

0

You need something like this:

<?php 
if ( isset( $_POST['submit'] ) ) { 
  echo $_POST['sel'];
}
?>
 <form action="" method="post">
<select name='sel'>
 <option value='Year 1'>Year 1</option>
 <option value='Year 2'>Year 2</option>
</select>
<input type="submit" name="submit" class="btn" value="submit">
</form>
nsthethunderbolt
  • 2,059
  • 1
  • 17
  • 24
  • i did the same thing that you have expressed.But it did not give any answer.Actually what I wanted to do is,to print the value according to the changes which I will make to the selection of the drop down list.Your consideration is highly appreciated. – VOSH Jul 13 '14 at 08:51
  • Then you will have to go with jquery/javascript..follow @rdanusha 's answer – nsthethunderbolt Jul 13 '14 at 08:56
  • and if you still for some reason want to do it in php, consider the link : http://stackoverflow.com/questions/3976222/php-on-select-change-post-form-to-self – nsthethunderbolt Jul 13 '14 at 08:58
-1

You can use Jquery instead of using PHP.

Code:

<html>

  <p id="showoutput">Display Text</p>

  <select name="cmb1" id="cmb1">
     <option value="val1">YOUR TEXT 1<option>
     <option value="val2">YOUR TEXT 2<option>
     <option value="val3">YOUR TEXT 2<option>
  <select>

  <script>
     $('#cmb1').on('change', function() {
       $('#showoutput').html($(this).val());
     });
  </script>
</html>
rdanusha
  • 913
  • 3
  • 15
  • 24