1

Hi I am trying to get the Radio button value from my jade page into the js file and unable to achieve it. I wish to show the value taken from the form to be displayed as a table format on the browser.

The radio button value does not reach the js file itself as i have tried with console.log option

I have tried with function calls and it does not seem to achieve either. Below is my jade file which I am trying to send it to js file

doctype
    html
    head
       title Add new comment
   body
     h3 Comment Details
   form(id='form', method='post', action='/comment/create')
    print Select the severity
  <br/>
  input(type='radio',name='severity',value ='Minor', onclick = 'func(type)')
  print Minor &nbsp
  input(type='radio',name = 'severity')
  print Major &nbsp
  input(type='radio',name = 'severity')
  print Critical &nbsp
  <br/><br/>
  input(type='submit', value='Add Comment')


    var CommentApi = require('../data/CommentApi');
        var express = require('express');
        var router = express.Router();

         router.get('/', function(req, res) {
          CommentApi.getAllComments(function(err, items) {
           res.render('comment/index', {title: 'Comments', comments: items})
        });
    });

router.get('/create', function(req, res) {
    res.render('comment/create');
});

function func()
 {
   var type = document.getElementByName("severity");
   console.log('type');
 }

router.post('/create', function(req, res) {
  var comment = {};
  console.log('type');
  comment.author = req.body.author;
  comment.text = req.body.text;
  comment.severity = req.body.severity;


     comment.crdate = req.body.crdate;
      commment.rdate = req.body.rdate;
      CommentApi.saveComment(comment, function(err, comment) {
          res.redirect('/comment');
      });
    });

1 Answers1

0

Try this.

I think you mistakenly add "type" as a argument in the onclick event mapping, since your func() function doesn't have any parameter to receive.

input(type='radio',name='severity',value ='Minor', onclick = 'func()')
Alwin Jose
  • 696
  • 1
  • 5
  • 13
  • Please have a look at this https://stackoverflow.com/questions/9618504/how-to-get-the-selected-radio-button-s-value – Alwin Jose Aug 09 '19 at 13:49