2016-10-09 27 views
1

這是我的html內容時,我檢查了多個下拉選框我想調用一個Java腳本函數,但它不工作。我使用jQuery的多選multiselect jquery多選複選框下拉調用一個事件時檢查和未選中

<select name="langOpt2[]" multiple id="langOpt2"> 
    <?php foreach($property_type as $row) { ?> 
     <option value="<?php echo $row['type']; ?>" onchange="selectsearch(this.checked,'property_type',this.value);"><?php echo $row['type']; ?> </label> 
     </option> 
    <?php } ?> 
</select> 

我的javascript代碼 -

<script language="javascript"> 
function selectsearch(val2,val1,state_id) 
    { 

    var title=state_id; 
    alert('action'); 
    $.ajax({ 
    url: '<?php echo base_url(); ?>index.php/property/propertysearch', 
    data: {'title':title,'name':val1,'status':val2 }, // change this to send js object 
    type: "post", 
    success: function(data){ 
    //document.write(data); just do not use document.write 
    console.log(data); 
    document.getElementById('search').innerHTML = data; 
    document.getElementById('search').style.display = 'block'; 
    document.getElementById("search1").style.display = 'none'; 
    }, 

    error: function() 
    { 
    alert("Fail") 
    } 

    }); 

    } 
</script> 
+0

你有在控制檯中的任何錯誤? – Blinkydamo

+0

沒有,當我檢查沒有js電話。檢查時沒有任何反應 – devendra

+0

嘗試將'onchange()'更改爲'onclick()' – Blinkydamo

回答

1
<select name="langOpt2[]" multiple id="langOpt2" > 
    <option value=""></option> 
    <option value="type1" onclick="selectsearch(this.selected, 'property_type', this.value)">Type 1</option> 
    <option value="type2" onclick="selectsearch(this.selected, 'property_type', this.value)">Type 2</option> 
</select> 

變化this.checkedthis.selected

相關問題