Question
Hello, I am trying to get the code below to work and am getting errors and it isn't working. Can you take a look at
Hello,
I am trying to get the code below to work and am getting errors and it isn't working. Can you take a look at the HTML and the external js files below and help me to get this running. This is the description of the assignment:
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will prompt the user to enter in the number of volunteers, event date, organization name, and host name. Using the number of volunteers entered (510), the script should loop through to ask the user to enter the recipient name and store it in an array. Once the user has entered all of the names and pressed submit, the page should display each of the invitations one after another at the bottom of the page.
Directions
Use the invitation.html file that you submitted in your previous assessment to add functionality to your form. This new functionality should allow the user to enter in the number of volunteers, whereupon the form will display the corresponding number of input fields for the user to enter information for each volunteer. Once the form is submitted, the data should be stored in an array to be looped through to create separate invitations for each volunteer on a new page.
Make sure to do the following:
- Add an input field that allows the user to input the number of volunteers as a numeric value.
- Once the number of volunteers has been entered (by pressing the enter key while the cursor is in the input field), use JavaScript to display the volunteer input fields based upon the number of volunteers entered.
- Write JavaScript that stores the form into an array of records once the form is submitted.
- Write JavaScript to Loop through the array of records and then display the invitation message for each volunteer. (Unlike a simple array that contains a single variable for each index, an array of records allows us to store related data fields for each index in the array. If we were going to store this in simple arrays, we would need a separate array for each data field.)
- Once completed, view your pages in each of your two selected Web browsers to see if the content renders appropriately and consistently within each. Next, verify that your code is error-free using the appropriate browser-specific development tool found in the Resources. Take a screen capture of each of your validation results and save it for submission.
HTML:
You have been invited to volunteer for an event held by organizationName on eventDate. Please come to the following website: websiteURL to sign up as a volunteer.
Thanks!
hostName
JavaScript:
let invitation = {}; //Create invitation object that properties will be added to later let recipientNames = []; //Create array for recipient names to be added to later
//Creating function to disable the form if function disableForm (x){ document.getElementById("form").style.display = "none"; var html = ""; //html object for (var i=0;i
"; } html += "" var special = document.getElementById("RecipientNamesForm"); special.innerHTML = html; } function completeInvitation() { //Console log method to log an object in the console console.log("Start here"); /*converts its first argument to a string, parses that string, then returns an integer or NaN*/ x = parseInt (invitation["NumberOfRecipients"]); for (var i=0;i
function create_invitation() //Function to replace placeholders in invitation { // Variable RecipientName to store value of recipientName from form invitation["NumberOfRecipients"] = document.getElementById("recipientName_form").value;
// Variable OrganizationName to store value of organizationName from form invitation["OrganizationName"]= document.getElementById("organizationName_form").value; // Variable EventDate to store value of eventDate from form invitation["EventDate"] = document.getElementById("eventDate_form").value; // Variable WebsiteURL to store value of websiteURL from form invitation["WebsiteURL"] = document.getElementById("websiteURL_form").value; // Variable HostName to store value of hostName from form invitation["HostName"] = document.getElementById("hostName_form").value; return false; //Form field validation if(invitation["NumberOfRecipients"] == "" || invitation["OrganizationName"] == "" || invitation["EventDate"] == "" || invitation["WebsiteURL"] == "" || invitation["HostName"] == "") { alert("All fields are required"); return false; }
//Checking the number of recipients input is a number if(isNaN(invitation["NumberOfRecipients"])){ alert("The Number of Recipeints entered is not a number, please enter a number."); return false; } disableForm(invitation["NumberOfRecipients"]); return false; }
Thank you,
Annette
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started