简体   繁体   中英

Populating a hidden field Microsoft JScript runtime error: Object doesn't support this property or method

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
              }


  }

I believe .value is the issue here. Since you are using jQuery, use this: .val()

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

I solved it thank you

hid.value = hid.value + opt.text + ',';
Dim data As String = HiddenOptions.Value.TrimEnd(","c)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM