Can one of you experts please help resolve this problem?
I have this js:
- <script type="text/javascript">
$(window).load(function () {
$("#txtFromDate").datepicker();
$('#timeStart').timepicker({ showPeriod: true,
onHourShow: OnHourShowCallback,
onMinuteShow: OnMinuteShowCallback
});
- $("#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();
- var eDate = $("#txtToDate").val();
var eTime = $("#timeEnd").val();
- var startDate = new Date(sDate + " " + sTime).getHours();
var endDate = new Date(eDate + " " + eTime).getHours();
- //Calulate the time difference
var hourDiff = endDate - startDate;
//alert(hourDiff);
- //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;
}
- //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:
- document.getElementById("gvCustomers_ctl02_hdReserve").href += ( "&hoursdiff=" + hoursDiff );
which gives me the following error:
Error: Unable to get property 'href' of undefined or null reference
Then I tried:
- document.getElementById("<%=hdReserve.ClientID %>").href += ("&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.
- <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