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 quotation marks of echo "...";
, you should "escape" the quotation marks like this:
echo
" ...
<script type='text/javascript'>
...
$(\"input[name='enable']\").click(function(){
Other than $
of jQuery or other variables within "normal quotes" can be confused with PHP variables
However escaping multiple quotes is something that takes a lot of time, so I recommend two simpler ways if you have more HTML in the script than PHP would in fact be interesting to isolate PHP and HTML using alternative PHP syntax , 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 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: