开发者

multiple selection in drop down list in span tag

开发者 https://www.devze.com 2023-03-14 05:18 出处:网络
my requirement is print the multiple selection data in dropdown list. i tried this but it doesn\'t work. i dont know where i miss the logic. please correct me. here my code

my requirement is print the multiple selection data in dropdown list. i tried this but it doesn't work. i dont know where i miss the logic. please correct me. here my code

    function getState() {
                ................
        document.getElementById('statediv').innerHTML=http.responseText;                        
                        http.send(params);

}

within body

    <div>   
        <h1 class="float-left">Create Annual Reports</h1>
        <div class="clear"></div>           
    </div>  
    <form  method="post" target="_blank"   action="<?=base_url();?>reports/prepareannualreport"  onsubmit="return fnValidate();" >
    <div id="registerform"> 
        <p></p> 
        <span class="float-left">State</span>
        <span id="statediv"><select name="multiple" id="multiple" multiple="multiple"><option value="0">(Select)</option></select>
</span>

In the dropdown list data successfully displayed. now when i choose multiple data in dropdown i want to print those values so i used the following function to print.

<script>
    function displayVals() {
      var singleValues = $("#single").val();
      var multipleValues = $("#multiple").val() || [];
      $("p").html(" <b>Multiple:</b> " + 
                  multipleValues.join(", "));
   开发者_Go百科 }

    $("select").change(displayVals);
    displayVals();

</script>

if i replace body content with the following functions it prints the selected data in dropdown.

<select id="multiple" multiple="multiple">
    <option selected="selected">Multiple</option>
    <option>Multiple2</option>
    <option selected="selected">Multiple3</option>
  </select>


$("select").live('click', function(){
    if($("option").is(":selected")) {
        $("p").append("Option Selected"+$(this).val()+"<br />")
    }
});

<select id="multiple" multiple="multiple">
    <option selected="selected">Multiple</option>
    <option>Multiple2</option>
    <option selected="selected">Multiple3</option>
  </select>

<p></p>

Working Jfiddle @ http://jsfiddle.net/xNmX2/


http://www.texotela.co.uk/code/jquery/select/# I use this plugin to manage the selects :) it's work perfectly..

0

精彩评论

暂无评论...
验证码 换一张
取 消