[英]What's wrong in this script?
When I submit the form and I try to get the Roomsno input value its showing like this-当我提交表单并尝试获取 Roomno 输入值时,其显示如下-
Array ( [0] => 1,2 );
why???为什么???
How can I send it so that it will come as a real array means like this- Array([0]=>1 [1]=>2)我怎样才能发送它以便它作为一个真正的数组出现,就像这样 - Array([0]=>1 [1]=>2)
<input type="hidden" class="form-control" name="Roomsno" id="Roomsno" required>
<script>
var rmidarray = []; // new Array()
var rmnoarray = [];
$('.roomtype').change(function() {
roomss_id = $(this).attr('data-id');
no_room = $(this).val();
var check = rmidarray.includes(roomss_id);
if (check == true) {
// alert('hi')
index = rmidarray.indexOf(roomss_id);
// alert(index);
rmnoarray.splice(index, 1, no_room);
// rmnoarray[index].push(no_room);
} else if (check == false) {
// alert('by');
rmidarray.push(roomss_id);
rmnoarray.push(no_room);
} else {
alert('No rooms Selected!!!')
}
$("#Roomsno").val(rmnoarray);
});
</script>
As the value is in array format so Rather than setting the value directly use jason.stringfy- Ex.由于值是数组格式,所以不要直接使用 jason.stringfy-Ex 设置值。
$("#Roomsno").val(rmnoarray); //Instead of this one
$('#Roomsno').val(JSON.stringify(rmnoarray)); //This one worked for me
And when i try to get the value i use json.decode and the value will come as array and we can use it normally as we use array.当我尝试获取值时,我使用 json.decode 并且该值将作为数组出现,我们可以像使用数组一样正常使用它。 The array will come like- Array([0]=>1[1]=>2)
数组会像 - Array([0]=>1[1]=>2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.