Few field values are not showing up in the final output, i'm using nodejs - html

index.html
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" id="fname" />
<input type="text" class="input" placeholder="Last Name" id="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>
the post request works properly but the names aren't showing up.
back-end nodejs file => serve.js
const express = require("express");
const fs = require("fs");
const bodyParser = require("body-parser");
const app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.get("/sign", (req, res) => {
res.send("Hello");
});
app.post("/sign", urlencodedParser, (req, res) => {
res.send(req.body);
let student = req.body;
let students = [];
students.push(student);
let data = JSON.stringify(students, null, 2);
fs.writeFile("./file.json", data, err => console.log("success"));
console.log(students);
});
const PORT = 5555;
app.listen(PORT, err => {
console.log(`Server Running at port: ${PORT}`);
});
file.json: Output
[
{
"gender": "male",
"bday": "1999-07-05"
}
]
The value from "First Name" and "Last Name" fields aren't showing up in the final output.
No matter what I change I couldn't get it to work properly.
Thank you in advance.

Try it
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" name="fname" />
<input type="text" class="input" placeholder="Last Name" name="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>

Related

HTML for multiple radio groups with the same name

What is the most accessible way to split a single radio form (same name) into groups? For example, choosing a time with the groups Today or Tomorrow?
Perhaps split them into two fieldsets?
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend>Today</legend>
<input type="radio" name="phone" id="a" value="a"/>
<label for="a">9am</label>
<input type="radio" name="phone" id="b" value="b"/>
<label for="b">12pm</label>
<input type="radio" name="phone" id="c" value="c"/>
<label for="c">5pm</label>
</fieldset>
<fieldset>
<legend>Tomorrow</legend>
<input type="radio" name="phone" id="d" value="d"/>
<label for="d">9am</label>
<input type="radio" name="phone" id="e" value="e"/>
<label for="e">12pm</label>
<input type="radio" name="phone" id="f" value="f"/>
<label for="f">5pm</label>
</fieldset>
</form>
The best approach seems to be using multiple fieldsets and in this particular example we want to clarify the legends as Graham Ritchie suggested. VoiceOver repeats the legend on each radio so it was redundant to add it to the label as well.
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend><span class="visually-hidden">Call me</span> Today</legend>
<input type="radio" name="phone" id="a" value="a"/>
<label for="a">9am</label>
<input type="radio" name="phone" id="b" value="b"/>
<label for="b">12pm</label>
</fieldset>
<fieldset>
<legend><span class="visually-hidden">Call me</span> Tomorrow</legend>
<input type="radio" name="phone" id="d" value="d"/>
<label for="d">9am</label>
<input type="radio" name="phone" id="e" value="e"/>
<label for="e">12pm</label>
</fieldset>
</form>
I updated the answer. Not sure you can do this with radio buttons but checkboxes and some javascript should do the trick.
function group1(e){
var id = e.target.id;
var boxes = document.getElementsByTagName('input');
for(let i=0;i<3;i++){
if (boxes[i].id != id)boxes[i].checked=false;
}
}
function group2(e){
var id = e.target.id;
var boxes = document.getElementsByTagName('input');
for(let i=3;i<6;i++){
if (boxes[i].id != id)boxes[i].checked=false;
}
}
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend>Today</legend>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="a" value="a"/>
<label for="a">9am</label>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="b" value="b"/>
<label for="b">12pm</label>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="c" value="c"/>
<label for="c">5pm</label>
</fieldset>
<fieldset>
<legend>Tomorrow</legend>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="d" value="d"/>
<label for="d">9am</label>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="e" value="e"/>
<label for="e">12pm</label>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="f" value="f"/>
<label for="f">5pm</label>
</fieldset>
</form>

Disable html form submit button until only fields with required attribute entered

I would like to hide the submit button of a html form until the required fields are entered, could anyone tell me how to do so?
here are my codes:
<form name="signup" action="mailto:chowhiuyu#gmail.com" method="post" enctype="text/plain">
Enter Student ID:
<input type="text" name="student_ID" size="30%" required >
<br>Gender: <input type="radio" name="gender" value="male" required>Male <input type="radio" name="gender" value="Female" required>Female
<br>Form:<select name="Form" required>
<option value="F1">F1</option>
<option Value="F2">F2</option>
<option value="F3">F3</option>
<option value="F4">F4</option>
<option value="F5">F5</option>
<option value="F6">F6</option>
</select>
<br>Electives chosen:
<input type="checkbox" name="Elective" value="Physics">Physics
<input type="checkbox" name="Elective" value="Chemistry">Chemistry
<input type="checkbox" name="Elective" value="Biology">Biology
<br>
<input type="checkbox" name="Elective" value="History">History
<input type="checkbox" name="Elective" value="Chinese History">Chinese History
<input type="checkbox" name="Elective" value="Music">Music
<input type="checkbox" name="Elective" value="Englit">English Literature
<br>
<input type="checkbox" name="Elective" value="Physical Education">Physical Education
<input type="checkbox" name="Elective" value="Visual Arts">Visual Arts
<input type="checkbox" name="Elective" value="business">Business Management
<input type="checkbox" name="Elective" value="Accounting">Accounting
<br>
Password:
<input type="password" name="password" placeholder="Password" id="password" size="30%" required>
<br>Re-enter Password:
<input type="password" name="password_check" placeholder="Confirm Password" id="confirm_password" size="30%" required>
<p>
<input type="submit" name="submit" value="Submit" onclick="window.alert('Your Request will be processed soon!');">
<input type="reset" name="Reset" Value="Reset">
</p>
Check out this http://jsfiddle.net/qKG5F/641/
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() == '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
})()
It will keep the button disabled if there is at least one field is empty.

How to check the array of radio buttons is checked or not?

Following is the html content and I want to check whether one of the radio button is checked or not?
<div class="col-sm-4 rating">
<input type="hidden" name="questionId[]" value="4"/>
<input type="radio" class="career_ratings" id="career_star31" name="career_rating_answer[3]" value="1" />
<label for="career_star31" title=""></label>
<input type="radio" class="career_ratings" id="career_star32" name="career_rating_answer[3]" value="2"/>
<label for="career_star32" title=""></label>
<input type="radio" class="career_ratings" id="career_star33" name="career_rating_answer[3]" value="3"/>
<label for="career_star33" title=""></label>
<input type="radio" class="career_ratings" id="career_star34" name="career_rating_answer[3]" value="4"/>
<label for="career_star34" title=""></label>
</div>
https://plnkr.co/edit/vlYNcBeEUkP0wLtcbqtV?p=preview
<!DOCTYPE html>
<html>
<body>
<form>
<div class="col-sm-4 rating">
<input type="hidden" name="questionId[]" value="4" />
<input type="radio" class="career_ratings" id="career_star31" name="career_rating_answer[3]" value="1" />
<label for="career_star31" title="1">1</label>
<input type="radio" class="career_ratings" id="career_star32" name="career_rating_answer[3]" value="2" />
<label for="career_star32" title="2">2</label>
<input type="radio" class="career_ratings" id="career_star33" name="career_rating_answer[3]" value="3" />
<label for="career_star33" title="3">3</label>
<input type="radio" class="career_ratings" id="career_star34" name="career_rating_answer[3]" value="4" />
<label for="career_star34" title="4">4</label>
</div>
<button onclick="check()">Try it</button>
</form>
<script>
function check() {
var radio = document.getElementsByClassName('career_ratings');
var x = false;
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
x = true;
}
}
alert(x)
}
</script>
</body>
</html>

Some fields are not posting with form

I have a form that partially works. I added the jquery star rating plugin and one additional field (subscribe) and neither one of them posts to the next page. I have used both name and id for the 'rating' radio buttons neither nor both worked. All of the other fields work fine.
<html>
<head>
<title>
</title>
<link type="text/css" rel="stylesheet" href="/css/jquery.rating.css" />
<style type="text/css">
#capcha div {
float: left;
}
.label {
width:100px;
float: left;/*Or however much space you need for the form’s labels*/
}
.error {
color: red;
}
.row {
margin-bottom: 5px;
clear:both;
}
#subscribe {
font-size: small;
color: gray;
}
</style>
<script src="/js/s3Capcha.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/jquery.rating.pack.js"></script>
<script type="text/javascript" src="/js/jquery.MetaData.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#capcha').s3Capcha();
$('.star').rating({
required: 'hide',
});
var id = $("#id").val(),
rating = $("#rating").val(),
name = $("#name").val(),
citystate = $("#citystate").val(),
email = $("#email").val(),
message = $("#message").val(),
subscribe = $("#subscribe").val(),
s3capcha = $('#capcha input:radio:checked').val();
var nameVal = $("#name").val();
if (nameVal == '') {
$("#name_error").html('');
$("#name").after('<label class="error" id="name_error">Please enter your name.</label>');
return false
}
else
{
$("#name_error").html('');
}
/// email validation
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $("#email").val();
if (emailaddressVal == '') {
$("#email_error").html('');
$("#email").after('<label class="error" id="email_error">Please enter your email address.</label>');
return false
}
else if (!emailReg.test(emailaddressVal)) {
$("#email_error").html('');
$("#email").after('<label class="error" id="email_error">Enter a valid email address.</label>');
return false
}
else
{
$("#response").html('');
}
jQuery.post("/s3verify.php",
{
id: id,
rating: rating,
name: name,
citystate: citystate,
email: email,
message: message,
subscribe: subscribe,
s3capcha: s3capcha
},
function(data) {
if (data === 'Fail') {
$("#capcha_error").html('');
$("#capcha").after('<div style="clear:both"></div><label class="error" id="capcha_error">Verify your pictures selection.</label>');
} else {
alert(data);
var obj = jQuery.parseJSON(data);
$("#listcomments" + obj.id).append("<div class='rentalcomments'><b>" + obj.score + "!</b> <span class='rentalcomments'>" + obj.message + "</span></div>");
$("#commentform").dialog('destroy').remove()
}
});
return false;
});
</script>
</head>
<body>
<?php
$ID = $_GET['ID'];
?>
<div style="padding:20px;autoflow:none;">
<form>
<input id="id" type="hidden" name="id" value="<?php echo $ID; ?>"/>
<fieldset>
<h3>Make your recommendation:</h3>
<div class="row">
<label class='label'>Rating</label>
<input id="rating" name="rating" type="radio" class="star" Value="1" title="Worst"/>
<input id="rating" name="rating" type="radio" class="star" Value="2" title="Bad"/>
<input id="rating" name="rating" type="radio" class="star" Value="3" title="OK" checked="checked"/>
<input id="rating" name="rating" type="radio" class="star" Value="4" title="Good"/>
<input id="rating" name="rating" type="radio" class="star" Value="5" title="Best"/>
</div>
<div class="row">
<label class='label'>Name</label>
<input id="name" name="name" size="30" type="text"/>
</div>
<div class="row">
<label class='label'>City, State</label>
<input id="citystate" name="citystate" value=""/>
</div>
<div class="row">
<label class='label'>Email</label>
<input id="email" name="email" size="30" type="email"/>
</div>
<div class="row">
<label class='label'>Comments</label>
<textarea id="message" name="message"></textarea>
</div>
<div class="row">
<label class='label'>Subscribe</label>
<input id="subscribe" name="subscribe" type="checkbox" value="1" checked />
<span>receive updates on comments made by you.</span>
</div>
<div id="capcha"> <?php include("s3Capcha.php"); ?> </div>
<div style="clear:both"></div>
<h3> Submit the form</h3>
<input type="button" id="button" value="submit"><br>
<label id="response"></label>
</fieldset>
</form>
</div>
</body>
</html>
You need to specify form action- to which page to send data to
<form action='next page url' method='POST'>
And for the button use-
<input type="submit" value="Submit">
May help!!
EDIT:
Change these-
<input name="rating" type="radio" class="star" Value="1" title="Worst"/>
<input name="rating" type="radio" class="star" Value="2" title="Bad"/>
<input name="rating" type="radio" class="star" Value="3" title="OK" checked="checked"/>
<input name="rating" type="radio" class="star" Value="4" title="Good"/>
<input name="rating" type="radio" class="star" Value="5" title="Best"/>
and in jquery -
rating = $(".star:checked").val()
or-
rating = $('input[type=radio]:checked').val()
Here's the problem:
rating = ("#rating").val();
should be....
rating = $('input:radio[name=rating]:checked').val();

how to save a list of data on playframework

add.html
#{form id:'addUserForm', action:#Users.Submit()}
#{field 'user.firstName'}
<div class="field">
<label for="${field.id}">First name : </label>
<input id="${field.id}" type="text" name="${field.name}" size="30" value="${field.value}" class="${field.errorClass}" /><span class="error">${field.error}</span>
</div>
#{/field}
this works
#{list user.department, as:'dep'}
#{field 'dep.id'}
<strong>Name: ${dep.name} </strong>
<input type="radio" name="${field.number}" value="0" checked>
<input type="radio" name="${field.number}" value="1">
#{/field}
#{/list }
this does not work :(
my problem is how to save a list in to the database
thanks