Click to See Complete Forum and Search --> : array-name maes problems in function
tobit
08-12-2003, 11:39 PM
hi
what is wrong?
if (document.lalalulu.bio_kat[1].selectedIndex == 0)
error: 'document.lalalulu.bio_kat.1' is null or not an object
what is wrong with this array name? when i use a normal name it works without anny probles.
tanks, ciao
Khalid Ali
08-13-2003, 01:45 AM
Probably
bio_kat[1].
is not an array...or the index is not there,
post your code that generates this error
tobit
08-13-2003, 11:10 AM
the array is a name of a <select> field (liek <select name="blablub[1]">).
that is because the name is dynamically produced, because the number of <select> fields is dynamic (i work with php).
when i use normal names it works, but wenn i use array names i doesnt.
Khalid Ali
08-13-2003, 11:23 AM
my guess is that your select is not being assigned a name..make sure you do that...change your logic for nameing the select boxes.(probably)
AdamGundry
08-13-2003, 11:30 AM
Here's something I stole from the PHP website (http://www.php.net/types.array):
Why array-style names won't work with Javascript is actually quite logical. If you take:
<input type="text" name="Settings[Name]">
as an example, then this JavaScript code:
document.forms.FormNameHere.elements.Settings[Name].value
won't work, of course! Name is an undefined constant in this case, as it's interpreted as a constant, not as a string... But adding quotes won't help you:
document.forms.FormNameHere.elements.Settings["Name"].value
Since the name="Settings[Name]" in the tag won't result in a "Settings"-subarray of the form.FormNameHere.elements array in the DOM.
The solution? Use this:
document.forms.FormNameHere.elements["Settings[Name]"].value
"Settings[Name]" is looked up in the elements array, and is found... The elements array is a hash, so strings can be used as keys!
Adam (sort of)
Originally posted by AdamGundry
Adam (sort of) lol... :D
tobit
08-14-2003, 01:03 PM
thanks for that answer, AdamGundry.
it works perfectly.
ciao, tobit