Click here to Skip to main content
15,888,351 members
Home / Discussions / JavaScript
   

JavaScript

 
Questionhow to add col dynamically using js and html Pin
Member 1368695921-Feb-18 1:03
Member 1368695921-Feb-18 1:03 
AnswerRe: how to add col dynamically using js and html Pin
Richard MacCutchan21-Feb-18 2:03
mveRichard MacCutchan21-Feb-18 2:03 
AnswerRe: how to add col dynamically using js and html Pin
ZurdoDev21-Feb-18 9:02
professionalZurdoDev21-Feb-18 9:02 
QuestionUsing JQuery on and off for events Pin
jkirkerx20-Feb-18 13:17
professionaljkirkerx20-Feb-18 13:17 
AnswerRe: Using JQuery on and off for events Pin
Richard Deeming21-Feb-18 8:07
mveRichard Deeming21-Feb-18 8:07 
GeneralRe: Using JQuery on and off for events Pin
jkirkerx22-Feb-18 7:31
professionaljkirkerx22-Feb-18 7:31 
Questionnodejs and WSDL Pin
dfgdsgjghiouyiouyol19-Feb-18 0:43
dfgdsgjghiouyiouyol19-Feb-18 0:43 
Question(NodeJS) ejs ignoring if statement if a css class is added to the element Pin
random_xyz12-Feb-18 5:08
random_xyz12-Feb-18 5:08 
I'm having a strange problem with ejs template engine in a nodejs, express app, that it's ignoring the if statement and showing the html inside if a css class is added to the html element. Here's the ejs code below:

This work and the if statement is effective:

JavaScript
<% if (typeof success !== "undefined") { %>
    //this works fine and the h4 only shows up if the if statement is true
     <h4><%= success %></h4>

<% } %>


This however show up on the page regardless:

JavaScript
<% if (typeof success !== "undefined") { %>
//this div is showing up regardless when adding the //bootstrap classes
        <div class="alert alert-success"><%= success %></div>
    <% } %>


I'll include the app.js code as well below if needed :

JavaScript
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const session      = require('express-session');
const bodyParser = require('body-parser');
const port       = 5000;
const mongoose = require('mongoose');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const flash = require('connect-flash');
const engine = require('ejs-mate');

const app = express();

app.use(logger('dev'));
app.use(bodyParser.json() );
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// view engine setup
app.engine('ejs', engine);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true
}));
app.use(flash());
app.use(function(req, res, next) {
  res.locals.currentUser = req.user;
    res.locals.error = req.flash("error");
    res.locals.success = req.flash("success");
    next();
});
//routes
const indexes = require('./routes/indexes');
const diaries = require('./routes/diaries');
const users = require('./routes/users');



// Configure passport middleware
app.use(passport.initialize());
app.use(passport.session());

// Configure passport-local to use account model for authentication
const db = require('./models');
passport.use(new LocalStrategy(db.User.authenticate()));

passport.serializeUser(db.User.serializeUser());
passport.deserializeUser(db.User.deserializeUser());
app.use('/users', users);
app.use('/', indexes);
app.use('/diaries', diaries);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

app.listen(port, ()=>{
  console.log(`App started on port ${port}`);
});
module.exports = app;


I've been going around in circles for awhile, so any help would be highly appreciated.
QuestionJquery: How to conditionally attach/detach bootstrap datepicker with textbox Pin
Mou_kol7-Feb-18 8:17
Mou_kol7-Feb-18 8:17 
AnswerRe: Jquery: How to conditionally attach/detach bootstrap datepicker with textbox Pin
Mou_kol7-Feb-18 8:22
Mou_kol7-Feb-18 8:22 
Questionjquery addClass and removeClass not working Pin
Mou_kol5-Feb-18 22:47
Mou_kol5-Feb-18 22:47 
AnswerRe: jquery addClass and removeClass not working Pin
Richard Deeming6-Feb-18 2:29
mveRichard Deeming6-Feb-18 2:29 
GeneralRe: jquery addClass and removeClass not working Pin
Mou_kol6-Feb-18 2:45
Mou_kol6-Feb-18 2:45 
GeneralRe: jquery addClass and removeClass not working Pin
Richard Deeming6-Feb-18 2:54
mveRichard Deeming6-Feb-18 2:54 
GeneralRe: jquery addClass and removeClass not working Pin
Mou_kol7-Feb-18 20:43
Mou_kol7-Feb-18 20:43 
GeneralRe: jquery addClass and removeClass not working Pin
Richard Deeming8-Feb-18 0:51
mveRichard Deeming8-Feb-18 0:51 
GeneralRe: jquery addClass and removeClass not working Pin
Mou_kol8-Feb-18 1:18
Mou_kol8-Feb-18 1:18 
GeneralRe: jquery addClass and removeClass not working Pin
Richard Deeming8-Feb-18 1:23
mveRichard Deeming8-Feb-18 1:23 
QuestionAutomatic calculation of Days and Filling of Months, Year Pin
Kiran Kumar31-Jan-18 9:13
Kiran Kumar31-Jan-18 9:13 
AnswerRe: Automatic calculation of Days and Filling of Months, Year Pin
F-ES Sitecore1-Feb-18 0:12
professionalF-ES Sitecore1-Feb-18 0:12 
QuestionEdit an Embed COde Api to implement on a website Pin
Member 1363973526-Jan-18 18:32
Member 1363973526-Jan-18 18:32 
Rant[REPOST] Edit an Embed COde Api to implement on a website Pin
Richard Deeming29-Jan-18 10:37
mveRichard Deeming29-Jan-18 10:37 
QuestionHow to open a java script in a android phone Pin
Member 1361672010-Jan-18 9:07
Member 1361672010-Jan-18 9:07 
AnswerRe: How to open a java script in a android phone Pin
debasish mishra23-Jan-18 19:09
professionaldebasish mishra23-Jan-18 19:09 
Questioni need fileration of html table and pagenation using Jquery or javascript but should support by IE8 Pin
irfankundi78631-Dec-17 6:37
irfankundi78631-Dec-17 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.