I am trying to populate a hidden field with the list box items. Currently I have a list box populating with the selected values. I need to somehow populate a hidden field with the values so that I can use them on a different page. So the hidden field value would be like 123456,654987,546845 etc. separated by a comma getting the values from the list box. I am kinda stuck with the code below not sure how to achieve this and I am currently getting the error Microsoft JScript runtime error: Object doesn't support this property or method. Any ideas?
<script language="javascript" type="text/javascript">
function getSelected(source, eventArgs) {
var s = $get("<%=DoctorNameTextBox.ClientID %>").value;
var opt = document.createElement("option");
opt.text = s.substring(s.length - 10);
opt.value = s.substring(s.length - 10);
document.getElementById('<%= NPIListbox.ClientID %>').options.add(opt);
var Source = document.getElementById('<%= NPIListbox.ClientID %>');
var Target = document.getElementById('<%= hidListBox.ClientID %>');
var HiddenList = document.getElementById('<%= hidListBox.ClientID %>') //The hidden field
var SelectedValue = Source.options[Source.options.selectedIndex].value + ','; // Hidden List is comma seperated
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = Source.options[Source.options.selectedIndex].text;
newOption.value = Source.options[Source.options.selectedIndex].value;
Target.options[Target.length] = newOption; //Append the item in Target
Source.remove(Source.options.selectedIndex); //Remove the item from Source
if (HiddenList.value.indexOf(SelectedValue) == -1) {
HiddenList.value += SelectedValue; // Add it to hidden list
}
else {
HiddenList.value = HiddenList.value.replace(SelectedValue, ""); // Remove from Hidden List
}
}