html - Why JQuery is not updating the hidden field -
i have divs inside updatepanel:
<asp:updatepanel runat="server" id="upadddays" updatemode="conditional"> <contenttemplate> <div class="adddayssection"> <div class="leftdiv2">task name: </div> <div class="rightdiv2" style="overflow: hidden;"> <asp:label id="lbltname" runat="server" text="" clientidmode="static"></asp:label> </div> </div> <div class="adddayssection"> <div class="leftdiv2">current due date: </div> <div class="rightdiv2"> <asp:label id="lblcurrdd" runat="server" text="" clientidmode="static"></asp:label> </div> </div> <div class="adddayssection" style="padding: 10px 0 10px 0; height: 45px;"> <div class="leftdiv2">add days extend: </div> <div class="rightdiv2"> <div style="float: left; text-align: right; padding-right: 5%; height: 100%;"> <span style="display: inline-block; height: 100%; vertical-align: middle;"></span> <img id="imgminus" src="../theimages/adddaysminus_off.png" style="vertical-align: middle; width: 35px; height: 35px; display: none;" /> </div> <div style="float: left; text-align: center;"> <span style="display: inline-block; height: 100%; vertical-align: middle;"></span> <input type="text" value="0" id="txtextend" maxlength="3" placeholder="number of days" size="3" class="txtextend" /> </div> <div style="float: left; text-align: left; padding-left: 5%; height: 100%;"> <span style="display: inline-block; height: 100%; vertical-align: middle;"></span> <img id="imgplus" src="../theimages/adddaysplus_off.png" style="vertical-align: middle; width: 35px; height: 35px;" /> </div> </div> </div> <div class="adddayssection"> <div class="leftdiv2">new due date: </div> <div class="rightdiv2"> <asp:label id="lblnewdd" runat="server" text="" clientidmode="static"></asp:label> </div> </div> </contenttemplate> </asp:updatepanel>
and hidden field somewhere else on page, outside of updatepanel:
<input type="hidden" id="newdd" name="newdd" runat="server" />
javascript:
$("body").on('click', "#imgplus", function (e) { //alert("plus"); var vdays = $("#txtextend").val(); $("#txtextend").val(parseint(vdays) + 1); vdays = $("#txtextend").val(); if (vdays > 0) { $("#imgminus").show(); } else { $("#imgminus").hide(); } var date = new date($("#lblcurrdd").text()); var days = parseint($("#txtextend").val(), 10); if (!isnan(date.gettime())) { date.setdate(date.getdate() + days); $("#lblnewdd").text(date.toinputformat()); alert($("#lblnewdd").text()); //displays: date $("#newdd").val($("#lblnewdd").text()); alert($("#newdd").val()); //displays: undefined } else { alert("invalid date"); } }); $("body").on('click', "#imgminus", function (e) { //alert("minus"); var vdays = $("#txtextend").val(); if (vdays > 0) { $("#txtextend").val(parseint(vdays) - 1); } var vdays = $("#txtextend").val(); if (vdays <= 0) { $("#imgminus").hide(); } else { $("#imgminus").show(); } var date = new date($("#lblcurrdd").text()); var days = parseint($("#txtextend").val(), 10); if (!isnan(date.gettime())) { date.setdate(date.getdate() - days); $("#lblnewdd").text(date.toinputformat()); alert($("#lblnewdd").text()); //displays: date $("#newdd").val($("#lblnewdd").text()); alert($("#newdd").val()); //displays: undefined } else { alert("invalid date"); } });
why isn't hidden value being updated date , displays undefined
instead?
because when set element runat="server"
, asp.net changes id, sou you'd have reference generated id of element through .clientid
property:
$("#<%=newdd.clientid %>").val()
Comments
Post a Comment