You start with:
echo
"
And in the middle of the code is this:
"input[name='enable']"
In other words, the quotation marks of "input[name='enable']"
are "breaking" the quotes of the echo "...";
, you should "escape" the quotes like this:
echo
" ...
<script type='text/javascript'>
...
$(\"input[name='enable']\").click(function(){
Aside from the $
jQuery or other variables within "normal quotes" may be confused with PHP variables
However escaping multiple quotes is something that takes a lot, so I recommend two simpler ways, if you have more HTML in the script than PHP would actually be interesting to isolate PHP and HTML using alternative syntax of PHP, so for example:
<?php if (codição): ?>
<script type='text/javascript'>
...
$("input[name='enable']").click(function(){
if ($(this).is(':checked')) {
$('input.textbox:text').attr('disabled', false);
} else if ($(this).not(':checked')) {
var remove = '';
$('input.textbox:text').attr ('value', remove);
$('input.textbox:text').attr('disabled', true);
}
});
...
</script>
<?php endif; ?>
Another way is to use the Heredoc
:
echo <<<EOF
<script type='text/javascript'>
...
$("input[name='enable']").click(function(){
if ($(this).is(':checked')) {
$('input.textbox:text').attr('disabled', false);
} else if ($(this).not(':checked')) {
var remove = '';
$('input.textbox:text').attr ('value', remove);
$('input.textbox:text').attr('disabled', true);
}
});
...
</script>
EOF;
Documentation:
To make it clear, the problem is to escape the double quotes inside the string in PHP. As quoted in the question I quoted, just do
$(\"input[name='enable']\")
, so the string will not be finished in PHP.– Woss