简体   繁体   中英

how to create filter drop down list based on another selections

i want to create filter drop down list on another selections in ejs ,both drop down list from mongo data base ..what should i do ? im susing node js

<label>Gender</label>
<select placeholder="Enter Your Gender">
  <option selected>Select Your Gender</option>
  <option>Male</option>
  <option>Female</option>
</select>
<label>Title </label>
<select name="title" placeholder="Enter Your Title">
  <%for(let t of title){%> //we can write(var ms = 0;ms< status.length; i++)instead of (let ms of maritalstatus)
  <option value="<%= t.male_english%>"><%= t.male_english%></option>
  <%}%>
</select>

app.js

app.get('/data-en', function(req, res, next) {
  let data = {} // data will send to page
  // get data from database
  db.collection('religious_category').find({}).toArray().then(religious => {
    data.religious = religious
    db.collection('list_of_marital_status').find({}).toArray().then(maritalstatus => {
      data.maritalstatus = maritalstatus

      db.collection('list_of_countries').find({}).toArray().then(countries => {
        data.countries = countries
        db.collection('honorifi_Title').find({}).toArray().then(title => {
          data.title = title

          res.render('data-en', data) // at the end
        })
      })
    })
  })
})

app.post('/data-en', (req, res, next) => {
  db.collection('newperson-en').insertOne(req.body, () => {
    res.redirect('/data-en')
  })
})

i have in database list of data for male and female i want when press on gender as male's list of title appear male titles and vice

You are passing an object called data to your template and you are trying to access an object named title .

You have to pass the properties of your object directly to your template:

res.render('data-en', {
        title: data.title,
        religious: data.religious,
        maritalstatus: data.maritalstatus,
        countries: data.countries
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM