0

I have added a small snippet of java script call underneath:

<button type="button" class="btn btn-secondary btn-sm" title="${tasksList[val]["command"]}"
                                    onclick="bootbox.alert({
                                        size: 'large',
                                        title: 'Job Command',
                                        message: '<pre>' + this.title + '</pre>'
                                    });">
                                    Job Command
                                </button></td>

the message looks like ssh serverdomain However, when I do:

 console.log(tasksList[val]["command"])

it shows the correct output i.e

ssh serverdomain "java -jar /local/folder --date=20190812"

I believe that the double quotes in the final output create some problem. Anyone knows how to get this correct? main focus should be this.title from the first code snippet.

It works fine for strings with no double quotes in there.

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
vc2310
  • 131
  • 1
  • 1
  • 7
  • double quotes and single quotes are interchangeable in javasctipt and html ... so if you want nested quotes, use `"blah'blah'blah"` or `'blah"blah"blah'` - in short, change `"command"` to `'command'` – Jaromanda X Mar 25 '20 at 23:34
  • title='${tasksList[val]["command"]}' with single quotes instead of double quotes title="${tasksList[val]["command"]}" – Dalorzo Mar 25 '20 at 23:36
  • 2
    [Don't use inline handlers](https://stackoverflow.com/a/59539045). They have too many problems: they have a demented scope chain (which requires global pollution), and they have string escaping issues. Use `addEventListener` instead – CertainPerformance Mar 25 '20 at 23:37

1 Answers1

0

Thank you for replying everyone. I realized either way I will be debating with having " or ' in my final message. Since the command is not given by me, it can change in future. I made a solution that I think will help overcome in both situations. Please let me know if this can be a wring solution.

<button type="button" class="btn btn-secondary btn-sm" title="${tasksList[val]["command"].replace(/\"/g, "&quot;")}"
                                    onclick="bootbox.alert({
                                        size: 'large',
                                        title: 'Job Command',
                                        message: '<pre>' + this.title + '</pre>'
                                        });">
                                    Job Command
                                </button>

vc2310
  • 131
  • 1
  • 1
  • 7
  • I believe this will work given the function of bootbox. This, then, is the answer for all scenarios with double quotes you might have. – Cannicide Mar 26 '20 at 00:04