0

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
              }


  }

4

2 回答 2

0

我相信 .value 是这里的问题。由于您使用的是 jQuery,因此请使用:.val()

http://api.jquery.com/val/

于 2013-09-16T19:19:20.107 回答
0

我解决了谢谢

hid.value = hid.value + opt.text + ',';
Dim data As String = HiddenOptions.Value.TrimEnd(","c)
于 2013-09-16T20:47:01.083 回答