这是我的html内容,当我检查多个下拉框复选框我想调用java脚本函数但它不起作用。我正在使用multiselect 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 :(得分: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.checked
更改为this.selected