填充隐藏字段Microsoft JScript 运行时错误:对象不支持此属性或方法

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

本文关键字:不支持 属性 方法 对象 字段 隐藏 Microsoft JScript 运行时错误 填充      更新时间:2023-09-26

我正在尝试用列表框项填充隐藏字段。目前,我有一个填充了所选值的列表框。我需要以某种方式用值填充隐藏字段,以便我可以在不同的页面上使用它们。 因此,隐藏字段值类似于 123456、654987、546845 等,由逗号分隔,从列表框中获取值。我有点坚持下面的代码,不确定如何实现这一点,我目前正在收到错误Microsoft JScript 运行时错误:对象不支持此属性或方法。有什么想法吗?

<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
              }

  }

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

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

我解决了谢谢

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