Display drop down selected option in php

2019-09-30 06:23发布

I want to display a simple html drop down box and selected value want to print.

<select name="v">
    <option value="fkt">Flipkart</option>
    <option value="snd">Snapdeal</option>
</select>

When the flipkart is selected php echo should print "Flipkart".
When the snapdeal is selected php echo should print "Snapdeal".

标签: php html
3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-30 06:42

Check for it.

  

    function shop(shop)
    {
         
        $("#show").val(shop);
    }
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select   onchange="shop(this.value)">
    <option value="Flipkart">Flipkart</option>
    <option value="Snapdeal">Snapdeal</option>
</select>
<br/>
<br/>

<input type="text" id='show'>

查看更多
迷人小祖宗
3楼-- · 2019-09-30 07:01
<select name="v" class='Product'>
    <option value="fkt">Flipkart</option>
    <option value="snd">Snapdeal</option>
</select>

<textarea class='showDescription'></textarea> <br>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(function(){
          $('.Product').change(function(){
                 var Product = $('.Product').val();
                 $(".showDescription").val(Product);
          });
    });
</script>
查看更多
你好瞎i
4楼-- · 2019-09-30 07:01

Use jQuery

$(document).ready(function(){
  $(".showDescriptionTextbox").val($(".Product").val());//to initialize
  $(".showDescriptionDiv").text($(".Product").val());//to initialize
  $(".Product").change(function(){
    $(".showDescriptionTextbox").val($(".Product").val());
    $(".showDescriptionDiv").text($(".Product").val());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="v" class="Product" id="dropdown">
    <option value="fkt">Flipkart</option>
    <option value="snd">Snapdeal</option>
</select>
<br/>
<br/>
value in textarea: <input type="text" class="showDescriptionTextbox">
<div>
or you can display value in div: <span class="showDescriptionDiv"></span>
</div>

查看更多
登录 后发表回答