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
19 odpowiedzi
+ 3
R_Chandra share your code from code playground, so that we can examine your code precisely.
+ 3
R_Chandra If you're still having problem, please push the code to github, and share it over here.
+ 1
R_Chandra did you set attribute value on input type="checkbox"?
+ 1
R_Chandra show your html code
+ 1
R_Chandra Your html consists of hidden codes which make invalid html code, no proper html input is formed.
+ 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) ;
}
+ 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
+ 1
Calviղ
It's working now. I was not using name attribute in the select tag.
Thank you
0
give your checkbox name attribute, say,
<input name="category" >
then, you can access it in the post router with
req.body.category
0
Gordon
I'm using get route for display all the request value from user. I've already given name attribute.
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.
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> <input type="radio" id="primary" value="primary" name="p">primary<br><br>
<input type="radio" id="secondary" value="secondary" name="p">secondary<br><br>
<input type="radio" id="high" value="high" name="p">high
0
<br><br><br><input type="submit" id="submit" value="submit" name="search">
<a href="types"> Show Types</a> <br>
<input type="text" id="fname" name="fname" ><br>
</div>
<div></div>
</form>
<script src="newserver.js"></script>
</body>
</html>
0
Calviղ
Unable to share the code. I just want to
to show selected data from dropdown on console using express
0
R_Chandra I mean do not share your code directly to reply here, paste code to code playground and share it here instead.
0
Calviղ
css file not included in the code playground
but it does work on my laptop
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.
0
..
.