Friday, 28 April 2017

how to edit dynamic dropdown list in nodejs mongodb handlebars

Hi i want to show all category value from mongodb database in dropdown list for edit ,but unable to do i'm stuck here.Guys Please give me some idea how do i do this, thanks in advance

crud.js (routing file)

router.get('/productEdit/:id',function (req,res,next) {
var productId = req.params.id;
Product.findById(productId,function (err,productedit) {
    if(err){
        return res.redirect('admin/404',{ title: 'Error Page',layout: 'adminlayout.hbs'});
    }
    res.render('admin/productEdit',{ title: 'Product Edit Page',producteditinfo:productedit,layout: 'adminlayout.hbs'});
});

});

productEdit.hbs (view file)

<div class="form-group">
   <label>Movie Category</label>
     <select class="form-control" name="catnames">
        <option value="">--- Choose Category ---</option> 
       <option value="Drama"  selected="selected" >Drama</option>
          <option value="Horror"  selected="selected" >Horror</option>
           <option value="Family"   
            selected="selected" >Family</option>
            <option value="Thriller"  selected="selected" >Thriller</option>
    <option value="Documentary"  selected="selected" >Documentary</option>
                 </select>
                       </div>



via Anshul Kumar

No comments:

Post a Comment