Hi all, i'm working on a php script and i got a little javascript. i'm trying to get information from some hidden fields but i keep getting an error, udefined. here are the codes:

var counter = 5;
var avail = document.getElementById['available_array[counter][0]'].value;

here is the original

tmp=document.order.elements['available_array[counter][\"+document.order.elements['BRANCHC[ ]'].selectedIndex+\"]'].value;
here is the select
<SELECT NAME="BRANCHC[ ]" SIZE=1  ID = "BRANCH_LIST>
and here is the hidden tag:

<input type="hidden" id="available_array[<?=intval($temp)?>][<?=$j?>]" name="available_array[<?=intval($temp)?>][<?=$j?>]" value="<?=$available_array[$i][$j]?>">

please tell me what im doing wrong

I guess you cannot have the id and name of an html element an number value or array value.

Hi all, i'm working on a php script and i got a little javascript. i'm trying to get information from some hidden fields but i keep getting an error, udefined. here are the codes:

var counter = 5;
var avail = document.getElementById['available_array[counter][0]'].value;

here is the original

tmp=document.order.elements['available_array[counter][\"+document.order.elements['BRANCHC[ ]'].selectedIndex+\"]'].value;
here is the select
<SELECT NAME="BRANCHC[ ]" SIZE=1  ID = "BRANCH_LIST>
and here is the hidden tag:

<input type="hidden" id="available_array[<?=intval($temp)?>][<?=$j?>]" name="available_array[<?=intval($temp)?>][<?=$j?>]" value="<?=$available_array[$i][$j]?>">

please tell me what im doing wrong

var counter = 5;
var avail = document.getElementById['available_array[counter][0]'].value;

The second line of the above means:
Assign to variable named "avail" the value of the document element that has id "available_array[counter][0]".
I guess that's not what you want to do...I can't think of any case where naming an element "available_array[counter][0]" would be a good idea.
Maybe you mean something like this?:

var counter = 5;
var strIdOfElementToGet = available_array[counter][0];
var avail = document.getElementById(strIdOfElementToGet).value;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.