I created a class for creating html inputs, ie createButton(). Below one is the class for creating optional parameters like onclick, style, class etc. I tried to pass the style, class and onclick parameters. but onclick dosen't work because of strings arrangements. Single quotes and double quotes are all confusing me.
$cmsform->setOption("style='margin-left: 10px !important;' class='submit' onclick='return confirm('Are you sure you want to delete this staff?')");
onclick='return confirm('Are you sure you want to delete this staff?')
Its breaking your code,
onclick='return confirm('
onclick code is working only till (' as it shows termination on '. You can use (\' for better representation and working.
Complete code line:
$cmsform->setOption("style='margin-left: 10px !important;' class='submit' onclick='return confirm(\'Are you sure you want to delete this staff?\')");
Hope this will solve your issue.
$cmsform->setOption("style='margin-left: 10px !important;' class='submit' onclick='return confirm(\'Are you sure you want to delete this staff?\')");
Try.
onclick='return confirm('Are you sure you want to delete this staff?')
will not work as html itsself.
1. add single quote to close the onclick
onclick='return confirm('Are you sure you want to delete this staff?')'
2. escape single quotes:
onclick='return confirm(\'Are you sure you want to delete this staff?\')'
3. escape the backslashes since you are using doublequotes in php
onclick='return confirm(\\'Are you sure you want to delete this staff?\\')'
so:
$cmsform->setOption("onclick='return confirm(\\'Are you sure you want to delete this staff?\\')'");
The error is because of this.
onclick='return confirm('Are you sure you want to delete this staff?')");
If you are confused you can escape the special charecter like this.
onclick='return confirm(\'Are you sure you want to delete this staff?\')'");
use \ to escape special charecters.
Hope that was any helpful!
The double quote is for php. The single quote in onclick='
is for html. The single quote in confirm('
is for JavaScript.
The problem here is that the single quote for JavaScript is conflicting with the single quote for html. You could change one of them to double quote, but then it would conflict with php. So you must escape one set of quotes. The ones you escape is up to you. Here is one possible solution.
$cmsform->setOption("style='margin-left: 10px !important;' class='submit' onclick='return confirm(\"Are you sure you want to delete this staff?\")'");