[英]Uncaught TypeError: Cannot set property 'innerHTML' of null when setting innerhtml for hiddenfield
im am trying to set the value for a hiddenfield with a bootstrap radio button.我正在尝试使用引导单选按钮设置隐藏字段的值。 I have an onCLick evnet on it and when it is clicked the value of the hiddenfield needs to be changed.
我有一个 onCLick evnet,当它被点击时,需要更改 hiddenfield 的值。 Here is the buttons and the hiddenfield.
这是按钮和隐藏字段。
<div class="myRow">
<div class="smallCol">
<div class="myRow">
<div class="smallCol title">
<asp:Label ID="lblNewRFID" runat="server" Text="RFID etiketcode"></asp:Label>
</div>
</div>
<div class="myRow">
<div class="smallCol">
<div class="btn-group hiddenRFIDValue" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Always')" id="alwaysRFID" value="Always" autocomplete="off">
Always
</label>
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Never')" id="neverRFID" value="Never" autocomplete="off">
Never
</label>
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Sometimes')" id="sometimesRFID" value="Sometimes" autocomplete="off">
Sometimes
</label>
</div>
</div>
</div>
</div>
<asp:HiddenField ID="hiddenRFIDValue" runat="server" />
and here is the script.这是脚本。
<script type="text/javascript">
onclick = function getHiddenRFIDValue(stringValue) {
document.getElementById('hiddenRFIDValue').innerHTML = stringValue;
}
</script>
Do any of you have an idear why i get the error?你们中有人知道为什么我收到错误吗?
You must remove "onclick" variable, only您必须删除“onclick”变量,仅
function getHiddenRFIDValue(stringValue) {
document.getElementById('hiddenRFIDValue').innerHTML = stringValue;
}
and和
<asp:HiddenField ID="hiddenRFIDValue" runat="server" />
try replace on尝试更换
<input type="hidden" ID="hiddenRFIDValue" runat="server" />
I fixed it with this.我用这个修好了。
<script>
$(".hiddenRFIDValue .btn").click(function () {
$("#MainContent_hiddenRFIDValue").val($(this).text());
});
</script>
When the HTML was generated it changed the id of the hidden field生成 HTML 时,它更改了隐藏字段的 id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.