RE: [PHP] Re: Variable name as a string

From: Date: Thu, 28 Aug 2008 14:40:13 +0000
Subject: RE: [PHP] Re: Variable name as a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278894@lists.php.net to get a copy of this message
At 11:50 AM +0100 8/28/08, Ford, Mike wrote:
On 28 August 2008 00:04, tedd advised: One of the ways to get around this is to:
<input type="checkbox" name="my_checkboxes[]" id="my_checkbox_1" value="1" >
That way php will use "name" and javascript will use "id".
Why??? <form name="my_form" ... >
     <input type="checkbox" name="my_checkboxes[]" ... >
</form> <script language="Javascript"> checkboxes = document.my_form["my_checkboxes[]"]; </script> Cheers! Mike
Mike: There is no "Why?", this is just another way to do it. In fact, there are other ways to accomplish this than what both of us have shown. What's nice about the technique I described here, at least for me, is that the "value" attribute applies to both name and id. PHP uses name and javascript uses id -- it's simple. However, I've been leaning to using getElementById() to create unobtrusive javascript, which can be used to isolate and use "name" as well, thus reducing the html code. I think my next demo will be to show these various techniques. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#278894) next »