-1

As the title says, I'm trying to use a var inside of a form name.

function validate_inventory_form(location){
    var name=document.inventory_+[location]+_input.name.value;

...

}

What would the correct syntax be to add the location to the form name so the var name would equal the result of document.inventory_cupboard_input.name.value for example?
Thanks in advance.

joepool
  • 5
  • 1
  • 4

1 Answers1

0

You can use bracket notation to access the property, this allow you to use a custom built string as the key.

Something like document["inv" + loc + "input]

kaosdev
  • 269
  • 1
  • 7