Reply to Re: [PHP] php and javascript

Your name:

Reply:


Posted by Richard Lynch on 04/12/05 01:45

On Sun, April 10, 2005 4:32 pm, Marek Kilimajer said:
> Assuming your form is named "Selection", you will have a javascript
> array document.forms['Selection'].elements['distID[]'] available. You
> can try:
>
> alert(document.forms['Selection'].elements['distID[]'][0].value);

I can GUARANTEE this will *NOT* work.

You *CANNOT* use [] as part of a 'name' in JavaScript.

No way, no how.

No matter how you quote it, embed it in a string, or try to sneak up on it.

It ain't gonna work.

'Cuz I tried every godamn reasonable (and quite a few UN-resaonable) ways
to do that. *

You'll just have to "know" that elements[7] is the one that you want.

Or maybe use an ID="xxx" attribute that does NOT have [] in it. But that
new-fangled ID attiribute was added long after I worried about this issue,
so you're on your own for that.

* In retrospect, you could probably write some kind of JavaScript function
that iterates through every single element, and compares its '.name' to
'distID' and to '3' (assuming you use distID[3] for a name) and then
return the one object you were looking for... But that would be horribly
inefficient JavaScript and would make your page dog-slow, so don't do
that.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация