1

Is there any way to submit a form when a user clicks on a checkbox? Think of a todo list.

When the user clicks on the checkbox, it updates the todo entry in the database saying its done.

Can this be done without using javascript?

6 Answers 6

6

You could use an image as a submit button:

<input type="image" name="done_5" src="checkbox_unchecked.gif" border="0">

That image would be an unchecked image of course, then reload with a checked version This button would follow the normal form action attribute

Sign up to request clarification or add additional context in comments.

Comments

1

Sorry.. without Javascript the answer is no. :-)

You may want to consider using AJAX form submission for something like that for user experience sake. At any rate the Javascript would look like this:

function submitForm() {
    document.myform.submit();
}

then use an OnClick="submitForm();" or OnChange="submitForm();"

7 Comments

Without JavaScript. The answer should be "no" :-)
Just saw your comment Johannes. Thanks
Lol... got so excited about Javascript I overlooked the "without Javascript" part of the question. :-)
This works but it's a bit overly complex, you don't need a function when you can just put the submission call in the onchange/onclick.
And I wrapped that in a function because where there is one checkbox, there are many = less code overall
|
1

Can this be done without using JavaScript.

No.

Comments

1

Use the "onclick" event on the checkbox to call the submit() function of the form in question.

In other words, "no" you need Javascript.

Comments

1

Not without using JavaScript, no. It's fairly simple, though:

<input type="checkbox" onchange="this.form.submit();">

Comments

1

Overlay the checkbox with a transparent submit element.

<div style="display: inline-block; position: relative;" >
    <input type="checkbox" checked >
    <input type="submit" value=""
        style="left: 0; height: 100%; opacity: 0; position: absolute; top: 0; width: 100%" >
</div>

Comments

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.