0

I have bridge_id. How can I concatenate the single quotation in JavaScript?

Javascript code:

$('input[type=checkbox][name=print_check]:checked').each(function(i){
  print_ids = print_ids+','+$(this).val();
});

Now it's appearing like this:

('B51622,D63766,J7473838,K884474,Y838383')

But I want it like this:

('B51622','D63766','J7473838','K884474','Y838383')

How can I generate a single quotation mark in JavaScript?

ADyson
  • 57,178
  • 14
  • 51
  • 63
Makizh
  • 1
  • 1
  • Not the best solution, but why not just add the `'`? `print_ids = print_ids+"','"+$(this).val();` then add a start/closing `'` after the loop: `print_ids = "'" + print_ids + "'";` – freedomn-m May 18 '22 at 10:46
  • Hi freedomm-m....it is coming like this not working ('CHCH-03S098XX6868686668'',''CHCH-03S098XX6868686668'','ANAN-01N098ZZ686868657...') – Makizh May 18 '22 at 10:58
  • Here's a working version: https://jsfiddle.net/6rtju8ns/ – ADyson May 18 '22 at 11:05
  • They you're putting the wrong `"` or `'` or too many. Here's ADyson's fiddle with my suggested change (yes, it adds an extra `'',` at the start, but it's only meant as a start / next step from what you had - ie just add the `'` around your values: https://jsfiddle.net/dLnx4r0e/ Here's a cleaner version using map: https://jsfiddle.net/dLnx4r0e/1/ – freedomn-m May 18 '22 at 11:34

0 Answers0