admin管理员组文章数量:1287809
I am using the following code to join the values of selectbox and add them to the textbox
$(document).ready(function () {
$('#ascuisines').on('change', function () {
$('#cuisineslisting').val($('#ascuisines').val().join());
}).trigger('change');
$('#asfeatures').on('change', function () {
$('#featureslisting').val($('#asfeatures').val().join());
}).trigger('change');
});
and my HTML Code is Like
<input type="text" name="cuisineslisting" id="cuisineslisting">
<select name="ascuisines" id="ascuisines" multiple="" class="chosen-select-width" required="">
<option value="" disable=""></option>
<option value="African">African</option>
<option selected="" value="American">American</option>
</select>
<input type="text" name="featureslisting" id="featureslisting">
<select name="asfeatures" id="asfeatures" multiple="" class="chosen-select-width valid" tabindex="-1" required="" aria-required="true" aria-invalid="false">
<option value="" disable=""></option>
<option value="Delivery">Delivery</option>
<option value="BYOB">BYOB</option>
<option value="Brunch">Brunch</option>
</select>
I don't know what's wrong but I am getting an error in my console as 'Uncaught TypeError: Cannot read property 'join' of null '
And this is still working in both application & JSFiddle but it changed the plete CSS properties of the selectbox.
If I ment either $('#cuisineslisting').val($('#ascuisines').val().join());
or $('#featureslisting').val($('#asfeatures').val().join());
then the CSS gets activated perfectly.
I am using the following code to join the values of selectbox and add them to the textbox
$(document).ready(function () {
$('#ascuisines').on('change', function () {
$('#cuisineslisting').val($('#ascuisines').val().join());
}).trigger('change');
$('#asfeatures').on('change', function () {
$('#featureslisting').val($('#asfeatures').val().join());
}).trigger('change');
});
and my HTML Code is Like
<input type="text" name="cuisineslisting" id="cuisineslisting">
<select name="ascuisines" id="ascuisines" multiple="" class="chosen-select-width" required="">
<option value="" disable=""></option>
<option value="African">African</option>
<option selected="" value="American">American</option>
</select>
<input type="text" name="featureslisting" id="featureslisting">
<select name="asfeatures" id="asfeatures" multiple="" class="chosen-select-width valid" tabindex="-1" required="" aria-required="true" aria-invalid="false">
<option value="" disable=""></option>
<option value="Delivery">Delivery</option>
<option value="BYOB">BYOB</option>
<option value="Brunch">Brunch</option>
</select>
I don't know what's wrong but I am getting an error in my console as 'Uncaught TypeError: Cannot read property 'join' of null '
And this is still working in both application & JSFiddle but it changed the plete CSS properties of the selectbox.
If I ment either $('#cuisineslisting').val($('#ascuisines').val().join());
or $('#featureslisting').val($('#asfeatures').val().join());
then the CSS gets activated perfectly.
- What CSS are you talking about? – Felix Kling Commented Aug 30, 2014 at 5:24
1 Answer
Reset to default 8From the .val()
documentation:
In the case of select elements, it returns null when no option is selected and an array containing the value of each selected option when there is at least one and it is possible to select more because the multiple attribute is present.
Assuming that "none selected is okay",
var selected = $('#ascuisines').val() || [];
$('#cuisineslisting').val(selected.join());
(Which utilizes the fact that the short-circuit ||
operator yields the first true-thy value of the operands.)
本文标签: javascriptUncaught TypeError Cannot read property 39join39 of nullStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property 'join' of null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741329279a2372675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论