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



The reason why... (I think)
Id defines the element as a part of the DOM - it is the identifier of the
element
Name tells the browser the name of the parameter (i.e. the mane to associate
with the value), not of the element.

PHP and JS are looking for two different things - one wants the element, one
the parameter - so it makes sense (sort of) to use two different terms.


Simcha Younger


-----Original Message-----
From: tedd [mailto:tedd.sperling@xxxxxxxxx]
Sent: Thursday, August 28, 2008 4:40 PM
To: php-general@xxxxxxxxxxxxx
Subject: RE: [PHP] Re: Variable name as a string

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.6.10/1638 - Release Date: 27/08/2008
19:06

.



Relevant Pages

  • RE: [PHP] Problem with MySQL
    ... that operator can be used to suppress error messages when calling ... Not that I'm necessarily advocating this as a technique, ...
    (php.general)
  • PHP security
    ... PHP and cannot seem to get it to work. ... The next technique I thought was quite interesting. ... only readable by the owner and Apache is running as the www-data user. ... Is that because Apache starts as a root owned process ...
    (Security-Basics)
  • Re: [PHP] PHP and #if
    ... If you are talking about simply commenting code out, yes, I am aware of this...however, the #if technique is far more capable in certain situations. ... I have to assume that PHP does not current provide such a technique...as I suspected. ... Is there a similar technique for PHP? ... To unsubscribe, visit: http://www.php.net/unsub.php ...
    (php.general)
  • Re: [PHP] PHP and #if
    ... On 14 Mar 2008, at 18:34, Eric Gorr wrote: ... the #if technique is far more capable in certain situations. ... There are reasons why C, etc. has included the ability to comment out lines of code and also provide #if's. ... I have to assume that PHP does not current provide such a technique...as I suspected. ...
    (php.general)
  • Re: Can a field communicate to a server and return information to another field without retrieving t
    ... If you are interested in a technique, ... article on how to dynamically populate drop-downs. ... You may not know PHP ... that you don't upset people all over the world. ...
    (comp.lang.php)