So my teacher gave us an assignment. Part of it is that if a checkbox is checked when I press a button, it will say whether the 'customer' is signed up for the newsletter or not. She hasn't taught us jquery, so I don't think that's what she wants us to use. Is there a way to do it without jquery?
This is my teacher's code in the body:
<div class="error"></div>
<label for="customerFirst">First Name:</label>
<input type="text" id="customerFirst">
<label for="customerLast">Last Name:</label>
<input type="text" id="customerLast">
<label for="customerEmail">Email:</label>
<input type="text" id="customerEmail">
<label for="customerNewsletter" style="font-weight: normal;">Check here to subscribe to the newsletter.</label>
<input type="checkbox" id="customerNewsletter" checked>
<button id="submit" onclick=Create()>Create Customer</button>
<button id="reset" onclick=Reset()>Reset Form</button>
In the script, I wrote this:
var customer = {
first: "",
last: "",
email: "",};
var Replace = function() {
customer.first = document.getElementById('customerFirst').value;
customer.last = document.getElementById('customerLast').value;
customer.email = document.getElementById('customerEmail').value;
}
var Create = function() {
Replace();
document.getElementById('customerList').innerHTML +=(customer.first + " " + customer.last + '\'s email is ' + customer.email +);
document.getElementById('customerFirst').value = "";
document.getElementById('customerLast').value = "";
document.getElementById('customerEmail').value = "";
}
var Reset = function() {
document.getElementById('customerFirst').value = "";
document.getElementById('customerLast').value = "";
document.getElementById('customerEmail').value = "";
document.getElementById('customerList').innerHTML = "";
}
Knowing how to check the checkbox will get me a lot closer to completing my assignment and make me seem a little less incompetent to my teacher. Thank you for any help.
Aucun commentaire:
Enregistrer un commentaire