In my view page i had a button
<button id="submit_btn" onclick="submitData('{{$data}}')">Save Data</button>
. If the $data
contains special characters like ' or "
the script will be resulted in an error. How can i handle this problem. Please help me.
Asked
Active
Viewed 1,579 times
0

Amal S R
- 870
- 7
- 21
-
Is your data an array? A string? An array of strings? – eResourcesInc Jan 08 '19 at 14:16
-
$data is string. it may contain ' or " – Amal S R Jan 09 '19 at 04:08
2 Answers
2
You can escape quote characters with addslashes()
<button id="submit_btn" onclick="submitData('{{addslashes($data)}}')">Save Data</button>
Also see this question

Mike Harrison
- 1,309
- 12
- 17
0
You should try this :
<button id="submit_btn" onclick="submitData({{$data}})">Save Data</button>