How can I use a checkbox onclick to submit my from.

How can I use a checkbox onclick to submit my from to its self.
Each time I check or uncheck my checkbox I want to be able the submit the form to its self so I can then update my db info via what's checked.

What I have below doesn't work
here is my current page
<script>
function doit_td()
{
if(document.getElementById('td').checked)
{
document.getElementById('td').value = 'checked';
return true ;
}
else
{
document.getElementById('td').value = '';
return true ;
}
}
</script>

<form name=dash action="" method=post>
<input type="checkbox" name="td" id="td" value="checked"  onClick="doit_td();">
</form>

quest_capitalAsked:
Who is Participating?
 
Ashish PatelConnect With a Mentor Commented:
before return true write this
document.dash.submit();
0
 
Ashish PatelCommented:
as no Action is provided it will submit to itself.
0
 
bugs021997Connect With a Mentor Commented:
@asvforce is indeed right...

The modified code looks as below...

<script>
function doit_td()
{
if(document.getElementById('td').checked)
{
document.getElementById('td').value = 'checked';
document.dash.submit();
return true ;
}
else
{
document.getElementById('td').value = '';
document.dash.submit();
return true ;
}
}
</script>

<form name=dash action="yourASPPage.asp" method=post>
<input type="checkbox" name="td" id="td" value="checked"  onClick="doit_td();">
</form>
0
 
Jai STech ArchCommented:
function doit_td()
{
if(document.getElementById('td').checked)
{
document.getElementById('td').value = 'checked';
document.forms[0].submit();
return true ;
}
else
{
document.getElementById('td').value = '';
document.forms[0].submit();
return true ;
}
}
</script>


<form name="dash" action="GIVE HERE THE NAME OF YOUR ASP FILE...test.asp" method="post">
0
 
CCongdonCommented:
If he wants the form to be submitted to itself for updating whether checked or unchecked as he has indicated, you'd just put this with the checkbox:

onclick="this.form.submit;()"

If you have an action already in the form, then change it to:

onclick="this.form.action='';this.form.submit();"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.