Not showing only the checkbox data on my console but showing all other data(radio button,textfield). Used req.body in get method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Not showing only the checkbox data on my console but showing all other data(radio button,textfield). Used req.body in get method

Express.js

14th Mar 2020, 8:29 AM
R_N
19 Answers
+ 3
R_Chandra share your code from code playground, so that we can examine your code precisely.
14th Mar 2020, 1:38 PM
Calviղ
Calviղ - avatar
+ 3
R_Chandra If you're still having problem, please push the code to github, and share it over here.
15th Mar 2020, 3:28 AM
Calviղ
Calviղ - avatar
+ 1
R_Chandra did you set attribute value on input type="checkbox"?
14th Mar 2020, 11:44 AM
Calviղ
Calviղ - avatar
+ 1
R_Chandra show your html code
14th Mar 2020, 1:04 PM
Calviղ
Calviղ - avatar
+ 1
R_Chandra Your html consists of hidden codes which make invalid html code, no proper html input is formed.
14th Mar 2020, 4:56 PM
Calviղ
Calviղ - avatar
+ 1
R_Chandra In html: Use <select id="district" name="district"> instead of <select id="district"> In node server side: app.post("/submit", function (req, res) { console.log(req.body.district) ; }
14th Mar 2020, 11:38 PM
Calviղ
Calviղ - avatar
+ 1
currently, your <input type="radio" name="p"> so, in your router, you use req.body.p req.body is an object req.body == { p:..., fname:... } for object, we get their values with the key
15th Mar 2020, 12:54 AM
Gordon
Gordon - avatar
+ 1
Calviղ It's working now. I was not using name attribute in the select tag. Thank you
15th Mar 2020, 4:06 AM
R_N
0
give your checkbox name attribute, say, <input name="category" > then, you can access it in the post router with req.body.category
14th Mar 2020, 9:56 AM
Gordon
Gordon - avatar
0
Gordon I'm using get route for display all the request value from user. I've already given name attribute.
14th Mar 2020, 10:37 AM
R_N
0
Calvin radio button is working fine but value selected from dropdown is not showing on the console. I'm using get route for display all the request value from user.
14th Mar 2020, 11:48 AM
R_N
0
Calviղ Front.htm <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <title>Front</title> </head> <div style = "background-color:lightblue"><h1 style="text-align:center">WELCOME</h1> </div> <body>  <form action="submit" method="POST">    <div class="nav"> <ul>   <li><a class="active" href="#home" >Home</a></li>   <li><a href="#contact">Contact</a></li>   <li><a href="#about">About</a></li> </ul> </div> <div class="div1">   District: <select id="district">  <option value="Gaya" name="g">Gaya</option>  <option value="Bihar" name="g">Muzzaffarpur</option>  <option value="Patna" name="g">Patna</option>  </select>  <br><br><br>  TYPE: <br>  <br>    &nbsp; &nbsp; &nbsp; <input type="radio" id="primary" value="primary" name="p">primary<br><br>              &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp;<input type="radio" id="secondary" value="secondary" name="p">secondary<br><br>                 &nbsp; <input type="radio" id="high" value="high" name="p">high  
14th Mar 2020, 1:14 PM
R_N
0
&nbsp; <br><br><br><input type="submit" id="submit" value="submit" name="search">          &nbsp;&nbsp;<a href="types"> Show Types</a> <br>          &nbsp;&nbsp;<input type="text" id="fname" name="fname" ><br>       </div> <div></div>   </form> <script src="newserver.js"></script> </body> </html>
14th Mar 2020, 1:17 PM
R_N
0
Calviղ Unable to share the code. I just want to to show selected data from dropdown on console using express
14th Mar 2020, 2:05 PM
R_N
0
R_Chandra I mean do not share your code directly to reply here, paste code to code playground and share it here instead.
14th Mar 2020, 3:25 PM
Calviղ
Calviղ - avatar
0
Calviղ css file not included in the code playground but it does work on my laptop
14th Mar 2020, 4:28 PM
R_N
0
Gordon app.post("/submit", function (req, res) { console.log(req.body) ; } This code is showing all the values (selected radio button, textfield value) except selected dropdown box.
14th Mar 2020, 5:12 PM
R_N
0
.. .
15th Mar 2020, 3:29 AM
Masterjoe
Masterjoe - avatar