0
const db = firebase.firestore();
function getDataOfBus() {
var dates = document.getElementById('departure-date').value.toString();
var fromd = document.getElementById('from-dest').value.toString()
var tod = document.getElementById('to-dest').value.toString()
console.log(dates + " -" + fromd + " -" + tod)

db.collection('Buses').where("DepartureDate", "==", dates).where("To", "==", tod).
where("From", "==", fromd).get().then((snapshot) => {
    let html = '';
    snapshot.forEach((busDatas) => {
        busData = busDatas.data()
          // console.log(busData.id)
          busData.docId = busDatas.id
        html += `
<div class="single-room-area d-flex align-items-center 
mb-50 wow fadeInUp" data-wow-delay="100ms" id="prince">

<div class="room-thumbnail">
  <img src="${busData.ImageLink}" alt="">
 </div>

<div class="room-content">

<h2><a href="javascript:getID('${busData.docId}');">${busData.TourName}</h2>
  <h6>${busData.From} to ${busData.To}</h6>
  <h4>₹ ${busData.SeatPrice} </h4>

  <div class="room-feature">
    <h6>Boarding Point  <span>${busData.BoardingTime}</span></h6>
    <h6>Dropping Point <span>${busData.DroppingTime}</span></h6>
    <h6>Seats Left <span>${busData.SeatsLeft}</span></h6>
    <h6>Total Time <span>${busData.TotalTime}</span></h6>
    <h6>Departure Date <span>${busData.DepartureDate}</span></h6>
  </div>


  </div>

</div>  `

        document.getElementById('bus-container-dynamic').innerHTML = html;

    })    // End foreach
})      // End then

}


function getID(id) {
  db.collection('Buses').doc(id).get().then((doc) => {
let html = '';
var data =  doc.data();
html += `<h1>${data.TourName} </h1>`
document.getElementById('div-1').innerHTML = html;
window.location = "single-bus.html"
}).catch((e) => {
console.log(e);
 })

}

I have performed this code to display the filtered documents in a html page where i am getting id of the document on which user clicks and i am not able to do this thing, i want to redirect it to "single-bus.html" on clicking and i want to send that id of to the next page "single-bus.html" where i want to use that id to display the datain the html file using that id.

<!-- single-bus.html-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
</head>
<body>
<div class="classer" id="div-1">

</div>
<script src="./loader.js"></script>
</body>
</html>
Divyanshu Bhaskar
  • 335
  • 1
  • 4
  • 15

1 Answers1

0

and sorry for my English.

As far as I understand, you want to send the document ID from page A to page B, using window.location.

Well, the next example is the solution I found.

Page A looks like this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

</body>

<script>
    // redirect user to some site with a parameter called 'documentParam' which value = 123
    window.location = 'some-site.html?documentParam=123'
</script>
</html>

Notices that parameters are placed in the URL using the question mark ?. If you need more parameters you can separate them usign & Read more about query parameters here: What is the difference between URL parameters and query strings?

Page B looks like this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

</body>

<script>

    // this page expects one parameter called 'documentParam'
    var urlParams = new URLSearchParams(window.location.search);

    console.log(urlParams.has('post')); // false --- no parameter called 'post'
    console.log(urlParams.get('documentParam')); // "123"

    alert(urlParams.get('documentParam'));
</script>
</html>

This solutions works using Query Parameters and reading them from the URL with JavaScript. I think you can adapt this idea to your needs.

You can read more here: How can I get query string values in JavaScript?

Abraham
  • 53
  • 1
  • 1
  • 4