1

how to do correct quotation for this

trHTML += '<tr><td>' + response[i].carrierName + '</td><td>' + response[i].serviceLevel + '</td><td>' + response[i].price + '</td><td>' + '<button id="buy-rate-button" onclick="getBuyingRate(' + response[i].carrierName + ',' + response[i].serviceLevel + ')" class="btn-primary btn-sm "><i class="fa fa-pencil-square-o"></i></button>' + '</td></tr>';
jeprubio
  • 17,312
  • 5
  • 45
  • 56
  • 1
    You need to put escaped quotes around the strings passed into your onclick method – Taplar Jan 08 '20 at 19:16
  • @Taplar Honestly looks like that isn't the case, as he is using ' to surround ". What is the issue OP? How do you want the string to look? – Libra Jan 08 '20 at 19:18
  • @Laif Single quotes are the string delimiter. They are not literals – Taplar Jan 08 '20 at 19:21
  • That isn't true at all. Both generate a string literal. See [here](https://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript) – Libra Jan 08 '20 at 19:23
  • `var x = 'I can use a " here because single quotes are delimiters.';` `var x = "I can use ' here because double quotes are delimiters.";` @Laif `var x = 'I cause an error because this ' terminates the string too soon.';` – Taplar Jan 08 '20 at 19:24
  • @Taplar Yes, that is exactly what I'm saying. That's what he did, put his code into a editor that will highlight the syntax for you, everything checks out. – Libra Jan 08 '20 at 19:26
  • https://jsfiddle.net/6jkexLr7/ No, the OP did not. @Laif – Taplar Jan 08 '20 at 19:26
  • `onclick="getBuyingRate(blah,blah2)"` <= if the values passed into the onclick method are expected to be literals, and not variable references, the strings are missing the quotes – Taplar Jan 08 '20 at 19:31

0 Answers0