Error when passing Javascript value from one page to another.

Error when passing Javascript value from one page to another.

Can one of you experts please help resolve this problem?

I have this js:

  1.   <script type="text/javascript">
                    $(window).load(function () {
                        $("#txtFromDate").datepicker();
                        $('#timeStart').timepicker({ showPeriod: true,
                            onHourShow: OnHourShowCallback,
                            onMinuteShow: OnMinuteShowCallback
                        });
  2.                     $("#txtToDate").datepicker();
                        $('#timeEnd').timepicker({ showPeriod: true,
                            onHourShow: OnHourShowCallback,
                            onMinuteShow: OnMinuteShowCallback
                        });
                        function OnHourShowCallback(hour) {
                            if ((hour > 20) || (hour < 6)) {
                                return false; // not valid
                            }
                            return true; // valid
                        }
                        function OnMinuteShowCallback(hour, minute) {
                            if ((hour == 20) && (minute >= 30)) { return false; } // not valid
                            if ((hour == 6) && (minute < 30)) { return false; }   // not valid
                            return true;  // valid
                        }
                        $('#btnSearch').on('click', function () {
                            var sDate = $("#txtFromDate").val();
                            var sTime = $("#timeStart").val();
  3.                         var eDate = $("#txtToDate").val();
                            var eTime = $("#timeEnd").val();
  4.                         var startDate = new Date(sDate + " " + sTime).getHours();
                            var endDate = new Date(eDate + " " + eTime).getHours();
  5.                         //Calulate the time difference
                            var hourDiff = endDate - startDate;
                            //alert(hourDiff);
  6.                         //Check if hour difference is less than 4 hours and show the message accordingly
                            if (hourDiff < 4) {
                                var r = false; $($("<div>A mininum of 4 hours is required!</div>")).dialog({ closeOnEscape: false, resizable: false, modal: true, open: function (event, ui) { $(".ui-dialog-titlebar-close").hide(); }, buttons: { Close: function () { r = false; $(this).dialog("close"); } }, close: function () { return r; } });
                                return false;
                            }
  7.                         //Add the check condition if the user is above the 4 hours time frame
                            if (hourDiff > 4) {
                                var r = confirm("There may be additional fees for going over the 4 hours!");
                                if (r == true) { // pressed OK
                                    return true;
                                } else { // pressed Cancel
                                    return false;
                                }
                            }
                        });
                    });
      </script>

The script above calculates the difference between start time and end time and determines whether a user is below, within or above 4 hour threshold.

It works quite well.

Let's assume this script along with markup is on a page called sender.aspx.

Once a user has selected start time and end time, the difference is stored in a variable called hourDiff.

We will like to pass the value of hourDiff from sender.aspx to receiver.aspx.

To do so, I have tried the following:

  1. document.getElementById("gvCustomers_ctl02_hdReserve").href += ( "&amp;hoursdiff=" + hoursDiff );

which gives me the following error:

Error: Unable to get property 'href' of undefined or null reference

Then I tried:

  1. document.getElementById("<%=hdReserve.ClientID %>").href += ("&amp;hoursdiff=" + hourDiff);

and that gives me the following error:

'hdReserve' is not declared. It may be inaccessible due to its protection level.

hdReserve is the control ID of the hyperlink I am using to pass values from sender.aspx to receiver.aspx.

I am only having problem on the javascript side.

However, here is the hyperlink with control Id of hdReserve.

  1.               <asp:HyperLink ID="hdReserve" style="color:#AA0000" runat="server" Text="Select"
                    Navigateurl='<%# String.Format("ReserveFacility.aspx?id={0}&groupsize={1}", Eval("siteId")) %>' />

Any ideas to resolve this?

Thank you so much in advance