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