My knowledge of JavaScript is limited, but I'm facing a problem with passing two values using the getElementID method. Is it possible to use this method twice as shown below or should I consider using another GetElementBy/GetElementsBy method to achieve this?
<script type="text/javascript">
$(document).ready(function () {
hash();
function hash() {
var hashParams = window.location.hash.substr(1).split('&');
for (var i = 0; i < hashParams.length; i++) {
var p = hashParams[i].split('=');
document.getElementById("<%=start.ClientID%>").value = decodeURIComponent(p[1]);
document.getElementById("<%=end.ClientID%>").value = decodeURIComponent(p[1]);;
}
}
});
</script>
UPDATE I have decided to duplicate the loop and it seems to be working although the values I am passing contain unwanted text that needs to be removed. Is there a way to cut off the split after a specific character? Here is my updated code snippet:
<script type="text/javascript">
$(document).ready(function () {
hash();
function hash() {
var hashParams = window.location.hash.substr(1).split('#');
for (var i = 0; i < hashParams.length; i++) {
var p = hashParams[i].split('=');
document.getElementById("<%=start.ClientID%>").value = decodeURIComponent(p[1]);
}
var hashParams = window.location.hash.substr(1).split('&');
for (var i = 0; i < hashParams.length; i++) {
var q = hashParams[i].split('=');
document.getElementById("<%=end.ClientID%>").value = decodeURIComponent(q[1]);;
}
}
});
</script>
The URL displayed in the search bar when redirecting from the previous page includes unnecessary characters. localhost:56363/Bookings.aspx#start=27/02/2018 12:30&end=27/02/2018 17:30"
Although the start and end input boxes are populated with values, the start input box has unwanted characters (&end) that need to be removed. Is there a way to avoid splitting after a certain character?