Вопрос

I have found a lovely bit of jQuery for a pop out calender. However I want to use the date(s) the user selects in a Stored Procedure. To keep this example simple how do I pull/push this date to say label?

I have tried putting the label into the function but without joy.

The date shows in <input type="text" id="datepickerStart" />

but not...

 <asp:Label ID="lbltest" runat="server" type="text" />

    <meta charset="utf-8" />

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
      $(function () {
          $("#datepickerStart").datepicker({
              showOn: "button",
              buttonImage: "images/calendar.gif",
              buttonImageOnly: true

          });
          $("#datepickerEnd").datepicker({
              showOn: "button",
              buttonImage: "images/calendar.gif",
              buttonImageOnly: true

          });
      });




  </script>
Это было полезно?

Решение

Another method I used to use was to declare the ID name as a variable in JavaScript, for example:

<script>
      var lbltest = '<%= lbltest.ClientId %>';
      function setLabel (yourDate)
      {
          $("#" + lbltest).text(yourDate);
      }

      $(function () {
          $("#datepickerStart").datepicker({
              showOn: "button",
              buttonImage: "images/calendar.gif",
              buttonImageOnly: true,
              onSelect: setLabel

          });
          $("#datepickerEnd").datepicker({
              showOn: "button",
              buttonImage: "images/calendar.gif",
              buttonImageOnly: true,
              onSelect: setLabel    
          });
      });

</script>

I have presumed you are using the Datepicker Widget from jQueryUI

As you can see, the "onSelect" property defines which function should be called when the user selects a date.

That then triggers the update of the label.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top