(on Sunday, 31 August 2008, 10:19 PM +0800):
> Thanks for your quick response !
> This not the perfect way , because in the javascript coding, we
> usually use document.forms['formName'].elements['elementName'] to get
> the element object ,
>
> <dt> </dt>
> <dd>
> <input type="hidden" name="public" value="0"><input type="checkbox"
> name="public" id="public" value="1"></dd>
>
> In the code, we use document.forms['formName'].elements['public'] to
> get the public checkbox, but it will only return the hidden input .
Use the ID of the element instead, as only the checkbox receives the id.
You can use the Javascript method document.getElementById(), or, if
using a more modern JS toolkit, use one of their convenience features
(in prototype, $('<id>'); in dojo, dojo.byId('<id>'); in jquery,
$('#<id>')).
> -------------------------------
> (on Sunday, 31 August 2008, 08:01 PM +0800):
> > But why should we add a hidden input ?
>
> To ensure a value is actually sent. When a checkbox is not checked, it
> does not send a key for that element when the form is submitted. Adding
> the hidden element ensures that the unchecked value is transmitted. This
> is done to ensure that a value for the element is always present.
>
> --
> Matthew Weier O'Phinney
> Software Architect | matthew@zend.com
> Zend Framework | http://framework.zend.com/
>
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论