Checkbox onclick submit this checkbox only?

Hi all,

New to JavaScript, but quite familiar with PHP. Am trying to get my head around this one. I have a dozen or so checkboxes in a form by themselves. I want whenever someone clicks a checkbox to automatically submit the form, but only to recognize the box that was checked.

Basically, I am trying to avoid cycling through the boxes in PHP and updating 12 rows when only one checkbox was clicked.

Any ideas?

Currently, I’m here: onclick=“this.form.submit();”

LOL. Not very far. :wink:

Thx!
JP


     [COLOR="Blue"] [B]onClick="document.form.submit()[/B];"[/COLOR]

:nono:

vijiruba, your code doesn’t really work.

jpfour23. Once a checkbox is checked it submits the form right? The checkbox’s value is then submitted, what is the exact problem you are having? Is it not submitting?

 
<body>

<form action="index.php">
<input type="checkbox" name="chk" onclick="if(this.checked){this.form.submit()}">
<input type="checkbox" name="chk" onclick="if(this.checked){this.form.submit()}">
<input type="checkbox" name="chk" onclick="if(this.checked){this.form.submit()}">
<input type="checkbox" name="chk" onclick="if(this.checked){this.form.submit()}">
</script>
 

Sorry, I should have clarified better. muazzez is on the right track. The problem then is if the box is already checked and I uncheck it.

Any ideas?

Thx,
JP

So you want to submit when the user unchecks it? You need to clarify this better…

Ok. I have 12+ checkboxes that are listed from a PHP array. Some will be checked, others may not be checked. When someone checks (or unchecks) a box, I want the form to submit, but only to submit the change that was made (essentially, the box that was checked).

In PHP language I would logically think…

IF Checkbox1 was changed, then update the database with this new value.

Make sense?

Thx,
JP

It sounds like you want some AJAX which can send information about the one change to the server instead of submitting the whole form, like the posted code examples show.

Before you use AJAX though, you should read up on JavaScript Best Practices.