[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

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>

0
quest_capital
Asked:
quest_capital
2 Solutions
 
Ashish PatelCommented:
before return true write this
document.dash.submit();
0
 
Ashish PatelCommented:
as no Action is provided it will submit to itself.
0
 
bugs021997Commented:
@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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now