1

I have a very simple question - how do I get a form to submit when I change the status of a checkbox

Here is my code

<form name="formName" id="formName" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
<input type ="checkbox" name="categories1" value = "1" onClick="submit();">1</input>
</form>

in addition to submit() I have tried:

  • this.form.submit()
  • document.getElementById('formName').submit()
  • this.parentNode.submit()

but none of these work. When I check or uncheck the box nothing happen

any clues?

Ross Farrelly
  • 267
  • 4
  • 11

4 Answers4

3

Refer to the form name attribute:

document.formName.submit()
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
iddo
  • 749
  • 3
  • 11
2

This works for me in both FF and IE:

<form name="formName" id="formName" action="" method="get">
<input type ="checkbox" name="categories1" value = "1" onclick="this.form.submit();">1</input>
</form>
Adam MacDonald
  • 1,958
  • 15
  • 19
1

found the problem - I had a submit button named submit - see Javascript form submit: Object doesn't support this property or method (IE7) for similar soln.

Community
  • 1
  • 1
Ross Farrelly
  • 267
  • 4
  • 11
0

You can try the following

<form name="formName" id="formName" action="" method="get">
<input type ="checkbox" name="categories1" value = "1" **onchange**="this.form.submit();">1</input>
</form>
Jerald
  • 335
  • 1
  • 10