Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24272
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Why checkbox field is not detected when the form is submitted? |
| Date | Tue, 20 May 2014 07:56:34 +0300 |
| Organization | A noiseless patient Spider |
| Lines | 38 |
| Message-ID | <llena0$e0i$1@dont-email.me> (permalink) |
| References | <149e228b-45da-4203-a4b9-6a01b089f257@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 20 May 2014 04:56:32 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="ad9d9996ed56b0226e850b84acbddfdf"; logging-data="14354"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UA0WYleZ3FGAtbNOdlg3Y" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
| In-Reply-To | <149e228b-45da-4203-a4b9-6a01b089f257@googlegroups.com> |
| X-Antivirus-Status | Clean |
| X-Antivirus | avast! (VPS 140519-1, 19.05.2014), Outbound message |
| Cancel-Lock | sha1:NsUNlhSy3fv2hD/Bk7OgWUrYDAE= |
| Xref | csiph.com comp.lang.javascript:24272 |
Show key headers only | View raw
2014-05-19 22:41, justaguy wrote: > The following fiddle js code for ON and OFF switch is very cool, > however, the checkbox field is not included the FORM when it is > submited, how come? Because it has no name attribute. Oh, and because the form can never be submitted when using the code in the jsfiddle: there is no submit button and not even any <form> element. > Please note, I've added name and value attributes to this checkbox. Not in the jsfiddle. > When the form is submitted and when checkbox is set to OFF then the > field and its value shows up in the FORM submission, hmm... > > http://jsfiddle.net/boweruk/DMfvx/7/ I don't think they do. If you add a `name` attribute to the `input` element, and if you add a <form> element and an input button, then a name=value pair is included in the form data upon submission when the checkbox is checked, not otherwise. The CSS code does not affect this; this is just how HTML elements are handled. The code does not contain any JavaScript, so I'm assuming you are asking how to fix the problem with JavaScript. The short answer is that you could add a hidden field into the form and set its value according to the checkbox setting. But this would be pointless in most contexts. Checkboxes are supposed to work so that name=value is included when the checkbox is on, not otherwise. Form handling, client-side and server-side, should be written to work with this (on the server, just check for the existence of a field with the name; you can check the value too, but that would be just data integrity check) rather than work around it. -- Yucca, http://www.cs.tut.fi/~jkorpela/
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why checkbox field is not detected when the form is submitted? justaguy <lichunshen84@gmail.com> - 2014-05-19 12:41 -0700
Re: Why checkbox field is not detected when the form is submitted? justaguy <lichunshen84@gmail.com> - 2014-05-19 13:01 -0700
Re: Why checkbox field is not detected when the form is submitted? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-19 23:55 +0200
Re: Why checkbox field is not detected when the form is submitted? dhtml <dhtmlkitchen@gmail.com> - 2014-05-19 16:42 -0700
Re: Why checkbox field is not detected when the form is submitted? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-05-20 07:56 +0300
Re: Why checkbox field is not detected when the form is submitted? Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-20 10:19 +0000
csiph-web