I've developed a html contact form. How do I capture the data which is entered in the form using JavaScript? (I can't use jQuery)? I think I need use document.GetElementById()
, but how? And do I need to use an event such as onBlur
to capture it when a user leaves the field, radio button, or checkbox?
/*Borders of fields for validation and indication*/
input:invalid{
box-shadow: 0 0 2px .5px red;
}
textarea:invalid{
box-shadow: 0 0 2px .5px red;
}
/*Spacing around fields this is in place of <br>*/
label{
display: block;
padding-top: 5px
}
<!DOCTYPE html>
<html>
<head>
<title>Contact Me</title>
<link rel="stylesheet" type="text/css" href="contactform_Lab8.css">
</head>
<body>
<form id="contactus">
<fieldset>
<label for="name">Name:</label>
<input id="name" type="text" name="name" autofocus required>
<label for="email">Email:</label>
<input id="email" type="email" name="email" required>
<label for="phone">Phone:</label>
<input id="phone" type="tel" name="phone" required>
<label for="status">Status:
<select id="status" name="status" required>
<option value="client">Client</option>
<option value="partner">Partner</option>
<option value="vendor">Vendor</option>
</select>
</label>
<label for="subscribe">
<input id="subscribe" type="checkbox" name="subscribe" value="check" checked>
Send me your newsletter</label>
<label for="sales">
<label for="support">
<input id="slsSupport" type="radio" name="slsSupport" value="sales" checked>Sales
<input id="slsSupport" type="radio" name="slsSupport" value="support">Support
</label>
</label>
<label for="msg">Message:</label>
<textarea id="msg" name="msg" rows="10" cols="30" required></textarea>
</fieldset>
<fieldset>
<button type="submit">Send</button>
<button type="reset">Reset</button>
</fieldset>
</form>
<script src="contactform_Lab8.js"></script>
</body>
</html>