Hi all, In have an hidden HTML array say.. <input type="hidden" name="gw_type[]" id="gw_type" /> Code (markup): ..now i want add values to the array/object via javascript For example i tried this but didnt work.. var gw_type = document.getElementById("gw_type"); gw_type.value[0] = "One"; gw_type.value[1] = "Two"; alert(gw_type.value[0]); Code (markup): But it always alerts "undefined". Please help me with this.
u can not store array in input. Better, do the textarea with visible:none; style and push elements into lines of textarea. Or... If u want to use nput, do as it in following: HTML <input type="hidden" name="my_arr" id="input_arr" value="" /> Code (markup): JS var input_arr = document.getElementById('input_arr'); function _push(elem, target) { target.value = target.value + elem + ";"; } _push("one", input_arr); _push("two", input_arr); Code (markup): after this, your html will be <input type="hidden" name="my_arr" id="input_arr" value="one;two;" /> ; - is a glue. If u want to make the array, use EXPLODE function (php, js).