public function confirmTransactionButton($confirmationFlag, $buttonName) {
$disabled = '';
$warningMessages = 'Watch Out';
$functionName = "return confirm(" . '\'' . "$warningMessages" . '\'' . ")";
if ($confirmationFlag == constant("Y.ENUM")) {
$disabled = 'disabled';
}
$button = "<input name='$buttonName' type='submit' class='BUTTON' id='$buttonName' onclick='$functionName' value='" . constant('KONFIRMASI.CON') . "' " . $disabled . " />";
return $button;
}
can anyone help me this issue, alert dialog won't appear.
i case i change string to number, its work
$warningMessages = 'Watch Out';
$functionName = "return confirm(" . '\'' . "$warningMessages" . '\'' . ")";
To
$warningMessages = '123';
$functionName = "return confirm(".$warningMessages.")";
The problem is hat you are using the same delimiter for the JS string and for the HTML attribute value, this terminating the attribute value prematurely. Look at the generated source and you will see:
It would look something like
<input ... onclick='confirm('foo')' />
Can you see the problem (the syntax highlighter helps)?
You can fix this by using different quotation marks:
$functionName = "return confirm(" . '"' . "$warningMessages" . '"' . ")";
// ^ ^
So your HTML will become
<input ... onclick='confirm("foo")' />
And of course the best solution would be to not use inline event handlers at all. Have a look at these articles to learn more about event handling.