1
<?php

echo '<input name="checkbox" value="student" type="checkbox" onclick=change(this, "type"); />';

?>

This isn't working. I keep getting in my console:

Uncaught SyntaxError: Unexpected token }

How do I input a string as a parameter for an onclick event?

<script>
        function change(cb, year) {
            var value = cb.value;
            var type = cb.checked;
            var yr = year;

            $.ajax( {
                type: 'POST',
                url:"process.php",
                data: { 'data':value, 'type':type, 'yr':yr, },
                success:function(result) {
                    console.log("works" + result);
                }
            });
        }
</script>

1 Answer 1

2

You have not wrapped your onChange function in double quotes :

echo '<input name="checkbox" value="student" type="checkbox" onclick="change(this, \'type\');" />';
Sign up to request clarification or add additional context in comments.

4 Comments

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/html/maine_journal/redesign/cp/index.php on line 78
Uncaught SyntaxError: Unexpected token ILLEGAL
I have updated my javascript for you to take a look at.
@user3537973 : check again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.