Conversation
| let name = document.querySelector('#contact_form').querySelector('#user_name'), | ||
| email = document.querySelector('#contact_form').querySelector('#email_this'), | ||
| number = document.querySelector('#contact_form').querySelector('#user_phone_number'), | ||
| textBox = document.querySelector('#contact_form').querySelector('#text-box'), | ||
| box = document.querySelector('#contact_form').querySelectorAll('input[type="checkbox"]'); |
There was a problem hiding this comment.
you can save the form reference so you get the elements faster. It is also better to use const since these values will never change. Grouping multiple variable definitions is not easy to read, so it's better if you keep them separated.
| let name = document.querySelector('#contact_form').querySelector('#user_name'), | |
| email = document.querySelector('#contact_form').querySelector('#email_this'), | |
| number = document.querySelector('#contact_form').querySelector('#user_phone_number'), | |
| textBox = document.querySelector('#contact_form').querySelector('#text-box'), | |
| box = document.querySelector('#contact_form').querySelectorAll('input[type="checkbox"]'); | |
| const form = document.querySelector('#contact_form'); | |
| const name = form.querySelector('#user_name'); | |
| const email = form.querySelector('#email_this'); | |
| const number = form.querySelector('#user_phone_number'); | |
| const textBox = form.querySelector('#text-box'); | |
| const box = form.querySelectorAll('input[type="checkbox"]'); |
| validateName(name); | ||
| validarEmail(email); | ||
| validatePhone(number); | ||
| validateChecBox(box); |
There was a problem hiding this comment.
| validateChecBox(box); | |
| validateCheckBox(box); |
| let valu = [name.value, email.value, number.value, validateChecBox(box), textBox.value]; | ||
| let pu = [" Name: ", "Email: ", "Phone number: ", "Courses: ", "Message: "]; | ||
|
|
||
| for (let index = 0; index < valu.length; index++) { | ||
| for (let ind = 0; ind < pu.length; ind++) { | ||
| showInfotmation(pu, valu); | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
you don't need to do this, in Javascript you can use objects as dictionaries:
let formValues = {
name: 'name',
email: 'email'
};
// and then you can access these key/pair values
for (const property in formValues) {
console.log(`${property}: ${formValues[property]}`);
}
In this way you don't need to do a double for loop which is performance heavy.
| let select = null; | ||
| let count = []; | ||
| for (let index = 0; index < courses.length; index++) { | ||
| if (courses[index].checked ==true) { | ||
| select = courses[index].value; | ||
| let show = count.push(select); | ||
| } | ||
| } | ||
| if(select == null){ | ||
| alert ('You have to select a course'); | ||
| } | ||
| return count; | ||
| }; |
There was a problem hiding this comment.
for some reason this validation is being executed twice and then a double alert is being displayed to the user, can you double check.
| return count; | ||
| }; | ||
|
|
||
| function showInfotmation(label, text=[]){ |
There was a problem hiding this comment.
| function showInfotmation(label, text=[]){ | |
| function showInformation(label, text=[]){ |
| <label for="email_this">E-mail address | ||
| <input id="email_this" name="Email" aria-required="true" > |
There was a problem hiding this comment.
| <label for="email_this">E-mail address | |
| <input id="email_this" name="Email" aria-required="true" > | |
| <label for="email">E-mail address | |
| <input id="email" name="Email" aria-required="true" > |
| <legend>Please select the courses thar are you interested in | ||
| <abbr title="required">*</abbr> | ||
| </legend> | ||
| <div id="course" > |
There was a problem hiding this comment.
| <div id="course" > | |
| <div id="course"> |
| <div> | ||
| <textarea name="message" id="text-box" cols="40" rows="10"></textarea> | ||
| </div> |
There was a problem hiding this comment.
| <div> | |
| <textarea name="message" id="text-box" cols="40" rows="10"></textarea> | |
| </div> | |
| <textarea name="message" id="text-box" cols="40" rows="10"></textarea> |
| <div> | ||
| <textarea name="message" id="text-box" cols="40" rows="10"></textarea> | ||
| </div> | ||
| <button>Send mesagge</button> |
There was a problem hiding this comment.
| <button>Send mesagge</button> | |
| <button>Send message</button> |
| </article> | ||
| </main> | ||
| <footer> | ||
| <p>This example was created <time datetime="2020-04-12 11:21">at 11:21 AM</time></p> |
There was a problem hiding this comment.
| <p>This example was created <time datetime="2020-04-12 11:21">at 11:21 AM</time></p> | |
| <p>This example was created at<time datetime="2020-04-12 11:21">11:21 AM</time></p> |
Dom exercise by Estefanía Sora