user2320325 user2320325 - 3 months ago 9
Javascript Question

How to concatenate variable in string in javascript

I am using this

var abc = jQuery('#pl_hid_addon_name').val();
alert(abc);

var atLeastOneIsChecked = jQuery('input[name="addon-"'+abc+']:checked').length ;
alert(atLeastOneIsChecked);


But it not worked
It should be after concatenate like below

var atLeastOneIsChecked = jQuery('input[name="addon-base-bar2[]"]:checked').length;

Answer
var atLeastOneIsChecked = jQuery('input[name="addon-"'+abc+']:checked').length;
                                                    ^
                                                    |

You used the closing " at the wrong place

var atLeastOneIsChecked = jQuery('input[name="addon-'+abc+'"]:checked').length;
                                                           ^
                                                           |