Vani
Vani

Reputation: 1353

jquery val() not working for hidden field

I have a hidden filed and trying to set a value inside a function . But its not working . Tried all the work around.

1.The .val() set is inside a function. 2.The function is not inside document.ready. If i move the function to document.ready , its not getting called.

         <script  type="text/javascript">
     $(document).ready(function () {
             $('#loadingModal').css('display', 'none');
             $('#loadingModal').css('left', '-500px');


         }); //end ready
         function buttonExportNotify() {
             debugger;
             blockUIForDownload();
         }

     var fileDownloadCheckTimer;
     function blockUIForDownload() {
         debugger;
         var token = new Date().getTime(); //use the current timestamp as the token value
         $("#download_token_value_id").val(token);

         $('#download_token_value_id').attr('value', token);
         //$.blockUI();
         $('#loadingModal').show();
         fileDownloadCheckTimer = window.setInterval(function () {
             var cookieValue = $.cookie('fileDownloadToken');
             if (cookieValue == token)
                 finishDownload();
         }, 1000);
     }
     function finishDownload() {
         debugger;
         window.clearInterval(fileDownloadCheckTimer);
         $.removeCookie('fileDownloadToken'); //clears this cookie value
         $('#loadingModal').hide();
     }</script>

HTML

   <input type="hidden" id="download_token_value_id" name="tri_download_token_value_id" runat="server"/>
  <asp:LinkButton ID="ExportExcel_LinkButton" runat="server" Text="Excel"   style="margin-left: 0px;" OnClientClick="buttonExportNotify()" ></asp:LinkButton>

//below line not working $("#download_token_value_id").val(token);

     $('#download_token_value_id').attr('value', token); 

Thanks

Upvotes: 1

Views: 556

Answers (1)

bradlis7
bradlis7

Reputation: 3479

My first thought is that maybe the id is being changed by ASP. Try setting clientidmode in your hidden field:

<input type="hidden" id="download_token_value_id" name="tri_download_token_value_id" runat="server" clientidmode="static" />

Upvotes: 1

Related Questions