Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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 Respostas
+ 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
..
.