MRizq
MRizq

Reputation: 271

Get value array in javascript

How to get value in javascript when input name/id generated by looping, just like this.

name="items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"

--js--
var form = document.forms[0];
var get = form.items[1AV08BBjan][srdnReqQty1AV08BBjan].value;

alert(get); //error missing ]

--js--

Any suggestion ?

Thanks
MRizq

Upvotes: 1

Views: 4687

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074335

If the name of the element really is

name="items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"

...as you've shown, then:

var form = document.forms[0];
var get = form.elements["items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"].value;

Live example

There's nothing special about the [ and ] characters within the name attribute of a form element at the HTML and JavaScript level. Some server-side technologies (like PHP) will look for those characters in the names of submitted form fields and turn them into arrays, but that's not an HTML or JavaScript thing.

Upvotes: 3

Related Questions