繁体   English   中英

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

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

我正在尝试使用列表框项目填充隐藏字段。 目前,我有一个列表框,其中填充了选定的值。 我需要以某种方式填充值的隐藏字段,以便可以在其他页面上使用它们。 因此,隐藏字段的值将类似于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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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