簡體   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