0

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.

Amal S R
  • 870
  • 7
  • 21

2 Answers2

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>