简体   繁体   中英

html/javascript/php run script onclick checkbox

This should be a very easy thing to do but I can't find a good reference on how to do it.

I want to submit a form upon clicking a checkbox. To make it a one click process and save user the step of clicking the check box and then clicking form submit, I'd like the form to be submitted upon clicking the checkbox.

My question is do I need to call a javascript function to do this or can html do this natively?

<form action="post.php" method="post"><input type="checkbox" name="done" id="done" value="1" onclick="post.php"></input></form>

doesn't seem to work. Do I have to call a javascript function, or am I missing something simple. Thanks

Try to replace

onclick="post.php"

By

onclick="submit();"

尝试onclick="this.parentNode.submit()"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM