Reputation: 3859
Is it possible to put an Array values to a hidden input field?
I am using ASP Classic code with javascript.
I have this asp code that puts every content of an Array to my hidden field.
Dim Data
For Each Data in aRecords(14)
Response.write "<INPUT type='hidden' name='hdn_field' value=""" & Data & """>"
Next
It appears in the view source like this:
<INPUT type='hidden' name='hdn_field' value="arrayvalue1">
<INPUT type='hidden' name='hdn_field' value="arrayvalue2">
But when i try to get the value of the "hdn_field" via javascript code. It doesn't work.
I call it by doing this (javascript):
testValue = document.frm_MainPage.hdn_field.value
I'm not sure if the mistake is in it's way of assigning it to hidden field or by the way i call it in javascript.
Please help.
Your help will be greatly appreciated.
Thank you.
Upvotes: 1
Views: 1587
Reputation: 10139
Because there are several hidden inputs with the same name, when you get the value of "hdn_field" you get all of those values in one go. To get only one value you need to give each hidden input a unique name.
Try something like this:
Dim length,i
length=ubound(aRecords)
for i=0 to length
response.write "<INPUT type=""hidden"" name=""hdn_field" & i & """ value=""" & aRecords(i) & """>"
next
Upvotes: 1
Reputation: 23801
Try iterating the value in the array into a delimited string or comma separated string and then assign in the hidden input field.When u get the value from hidden just split by comma to get the content of the array
Upvotes: 1