Question

In: Computer Science

In the previous assessment, you used a static set of named variables to store the data...

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 (5–10), 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.

My Previous assessment

HTML


Invitation Page



CapellaVolunteers.org


  • Home

  • Invitation

  • Gallery

  • Registration




Recipient name:

Organization name:

Event Date:

URL:

Host name:



Hello recipientName!



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

This events site is for IT-FP3215 tasks.

JAVASCRIPT

// The function to be executed when the form is submitted
function submitFunction() {
let rcpName = document.getElementsByName("recipientName")[0].value; //recipientName input is captured to a variabnle. [0] used because, it is the first value in the list
let orgName = document.getElementsByName("organizationName")[0].value; //organizationName input is captured in a variable
let evtDate = document.getElementsByName("eventDate")[0].value; //eventDate input is captured in a varibale
let webURL = document.getElementsByName("websiteURL")[0].value; //websiteURL input is captured in a variable
let hstName = document.getElementsByName("hostName")[0].value; //hostName input is captured in a variable.
  
document.getElementById("recipientName").innerHTML = rcpName; //In the response, the recipientName is replaced by the value of the variable
document.getElementById("organizationName").innerHTML = orgName; //In the response, the organizationName is replaced by the value of the variable
document.getElementById("eventDate").innerHTML = evtDate; //In the response, the eventDate is replaced by the value of the variable
document.getElementById("websiteURL").innerHTML = webURL; //In the response, the websiteURL is replaced by the value of the variable
document.getElementById("hostName").innerHTML = hstName; //In the response, the hostName is replaced by the value of the variable

}

This is the previous question (posting as per expert's comment). And the code attached was my answer to the previous question.

In this assessment, use the Web page called “invitation.html” found in the Required Resources (in the zip file called IT-FP3215.zip) to add functionality to an interactive form that generates an invitation to volunteers for an event. The file will have the following invitation message placeholder and a form below it. You will add JavaScript to the form that will allow a user to dynamically fill out the invitation.

Hello __recipientName_____!

You have been invited to volunteer for an event held by __organizationName_____ on ___eventDate_____. Please come to the following website: <insert your website URL> to sign up as a volunteer.

Thanks!

__hostName__

Hints:

  • The placeholders (for example the “recipientName”) will need to be set up as <span> elements with an assigned id attribute. Prompt the user to enter in the recipient’s name, organization name, event date, and host name. Using JavaScript, replace those elements dynamically with what the user has entered in the form.
  • Use the form’s input fields (once submitted) to store the values to JavaScript variables. Then manipulate the DOM to replace the <span> element content dynamically.

Tip: Variable names cannot include any special characters or spaces. They cannot start with a number. They also cannot be any of JavaScript’s reserved words.

Preparation

Download and unzip the IT-FP3215.zip file found in the Required Resources. It contains the initial framework for the site. All of the HTML files are located in the root directory. Images are placed in the images subdirectory; CSS files are placed under the css subdirectory. Your JavaScript external files should be placed under the “js” subdirectory (you will need to create it). When you submit your work, be sure to zip up the entire folder, including all of the ancillary files such as the images, CSS, and JavaScript code.

Note: This course requires you to use a text editor to complete your work. There are many free open source options on the Internet from which you may choose. See the Suggested Resources for links to free, open source text editors.

Directions

Read the Overview. Use the invitation.html file in the Resources as a template for completing this assessment.

Write JavaScript that enables the invitation to be dynamically completed using the form. Make sure to do each of the following:

  • Declare variables to store the input field data.
  • Store the input field data into the variables on form submit.
  • Manipulate the DOM to replace placeholder data with the variables.
  • Write developer comments to describe the variables being declared and explain the functions and logical blocks of JavaScript code.
  • 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.

This is assessment 2 for 'IT-FP3215 Introduction to JavaScript' course from Capella University

Solutions

Expert Solution

The below solution does contains comments for the sake of understanding. Simply you can run the below code to obtain the required results.

It does validate all the conditions which were stated in the question

Due to time constraint, I did not write the CSS code and apart from CSS it contains all the functionality

<!DOCTYPE>
<html lang="en-US">
<head>
    <title>Invitation Page</title>
    <!-- <link rel="stylesheet" type="text/css" href="css/main.css" /> -->
    <script>
        let invitation = {};
        let recipientNames = []; 
        function disableForm(n){
            document.getElementById("form").style.display = "none";
            var html = "";
            for(var i=0; i < n; i++) {
                html += "<lable>Recipient Name "+ (i + 1) +" <br> <\label><input type = 'text' class = 'name' > <br>";
            }
            html += "<input type = 'submit' id = 'recipientNamesSubmit' >"
            var special = document.getElementById("RecipientNamesForm");
            special.innerHTML = html;
        }


        function fillInvitations(){
            console.log("Start here");
            n = parseInt(invitation["NumberOfRecipient"]);
            for (var i =0; i < n; i++) {
                var name = document.getElementsByClassName("name")[i].value;
                if(name == "") { 
                    alert("All fields are required!.");
                    return false;
                }
                recipientNames.push(name);
            }
            console.log(recipientNames)
            var html = "";
            for(var i = 0; i< n; i++) {
                html += "Hello Recipient "+recipientNames[i]+"<br><br> You have been invited to volunteer for an event held by organization "+ invitation["OrganizationName"] + " on " + invitation["EventDate"] + " Please come on the following website: " + invitation["WebsiteURL"] + " to sign up as a volunteer. <br><br> Thanks! <br>" + invitation["HostName"] + "<br><br>";
            }
            document.getElementById("placeholderContent").style.display = "none";
            var special = document.getElementById("Content");
            special.innerHTML = html;
            return false;
        }


        function create_invitation() //Function to replace placeholders in invitation
        {
                // Storing Number of Recipient in a dictionary
                invitation["NumberOfRecipient"] = document.getElementById("recipientName_form").value;

                // Storing Organization Name
                invitation["OrganizationName"] = document.getElementById("organizationName_form").value;

                // Storing Event Date
                invitation["EventDate"] = document.getElementById("eventDate_form").value;

                // Storing Website URL
                invitation["WebsiteURL"] = document.getElementById("websiteURL_form").value;

                // Storing Host Name 
                invitation["HostName"] = document.getElementById("hostName_form").value;

                // Performing Some Validation
                if(invitation["NumberOfRecipient"] == "" || 
                   invitation["OrganizationName"] == "" || 
                   invitation["EventDate"] == "" || 
                   invitation["WebsiteURL"] == "" ||
                   invitation["HostName"] == "") {
                    alert("All fields are required!.");
                return false
                }

                // Making sure the Number of Recipient input is a Number
                if(isNaN(invitation["NumberOfRecipient"])) {
                    alert("Enter a Numeric for the Number Of Recipient Field.");
                    return false;
                }
            disableForm(invitation["NumberOfRecipient"]);
            return false;
        }  
    </script>
</head>
<body>
  
    <header>
        <div class="top">
            <a class="logo" href="index.html">CapellaVolunteers<span class="dotcom">.org</span></a>
        </div>
        <nav>
            <ul class="topnav">
                <li><a href="index.html">Home</a></li>
                <li><a href="invitation.html" class="active">Invitation</a></li>
                <li><a href="gallery.html">Gallery</a></li>
                <li><a href="registration.html">Registration</a>
                </li>
            </ul>
        </nav>
    </header>
    <section id="pageForm">
        <form id = "form" action="#" onsubmit="return create_invitation();">
          
            <label for="recipientName_form">Number Of Recipients: </label>
            <input type="number" name="recipientName_form" id="recipientName_form" placeholder="Enter your Recipient Name" /> <br>
            <label for="organizationName_form">Organization name: </label>
            <input type="text" name="organizationName_form" id="organizationName_form" placeholder="Enter your Organization Name" /> <br>
            <label for="eventDate_form">Event Date: </label>
            <input type="text" name="eventDate_form" id="eventDate_form" placeholder="Enter your Event Date" /> <br>
            <label for="websiteURL_form">URL: </label>
            <input type="text" name="websiteURL_form" id="websiteURL_form" placeholder="Enter your Website URL" /> <br>
            <label for="hostName_form">Host name: </label>
            <input type="text" name="hostName_form" id="hostName_form" placeholder="Host Name" /> <br>
            <input type="submit" value="Submit"> <br>
        </form>
        <form id = "RecipientNamesForm" onsubmit="return fillInvitations()">
            
        </form>
    </section>
    <article id="placeholderContent">
        Hello <span id="recipientName">recipientName</span>! <br/> <br/> 
        You have been invited to volunteer for an event held by <span id="organizationName">organizationName </span> on <span id="eventDate">eventDate</span>. Please come to the following website: <span id="websiteURL">websiteURL</span> to sign up as a volunteer.
        <br/>
        <br/> Thanks!
        <br/>
        <br/>
        <span id="hostName">hostName</span>
    </article>
    <article id = "Content"></article>
    <footer>This events site is for IT-FP3215 tasks.</footer>
</body>

</html>

Hope this helps you. Thanks


Related Solutions

We have a data set named "pp123" with the following variables, "highestgradecompleted", "earn," "age", and "agesquared."...
We have a data set named "pp123" with the following variables, "highestgradecompleted", "earn," "age", and "agesquared." Draft an R script with the following specifications (we aren't given the data file) and are asked just for the script. Regress "earn" on "highestgradecompleted," "age," and "agesquared" such that it evaluates whether highestgradecompleted" has a discrete effect at particular thresholds: having 12 years of schooling ("highestgradecompleted" values equaling 12); having less than 12 ("highestgradecompleted" values < 12); and having more than 12 years...
25. In Data Mining, ___ is a set of input variables used to predict an observation's...
25. In Data Mining, ___ is a set of input variables used to predict an observation's outcome class or continuous outcome value. 26. During each iteration of cluster analysis, the distances between new clusters are determined until any two clusters are sufficiently close to be linked using an algorithm called ___. 27. In the CRISP-DM process for data mining, which phase is the cleaning of the data so it is ready for modeling tools?
Using the data set from the previous question (scatterplot.xlsx). With the data point with the smallest...
Using the data set from the previous question (scatterplot.xlsx). With the data point with the smallest x value removed, the scatter plot now suggests a ________   ["nonlinear" OR "linear"]         relationship between the dependent and independent variables. Data: x y 45 2358 56 4204 26 287 54 3849 24 925 23 3273 34 -678 45 3748 47 2898 43 1974 32 226
You estimate a model with 9 explanatory variables and an intercept from a data set with...
You estimate a model with 9 explanatory variables and an intercept from a data set with 100 observations. To test hypotheses on this model you should use a t-distribution with how many degrees of freedom? Select one: a. 1 b. 10 c. 9 d. 90
Consider two models that you are to fit to a single data set involving three variables:...
Consider two models that you are to fit to a single data set involving three variables: A, B, and C. Model 1 : A ~B Model 2 : A ~B + C (a) When should you say that Simpson’s Paradox is occuring? A. When Model 2 has a lower R2 than Model 1. B. When Model 1 has a lower R2 than Model 2. C. When the coef. on B in Model 2 has the opposite sign to the coef....
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
Each value in the data set is called a ? .    Variables whose values are...
Each value in the data set is called a ? .    Variables whose values are determined by chance are called ? . A Blank 1 consists of all subjects (human or otherwise) that are being studied.    A Blank 1 is a circle that is divided into sections or wedges according to the percentage of frequencies in each category of the distribution.    Tell whether Descriptive or Inferential Statistics has been used. In the upcoming election, it is predicted...
A Guideline for Project I 1. Collect a data set with two related variables. You can...
A Guideline for Project I 1. Collect a data set with two related variables. You can create your own data set or can download a data set from a web or to use data sets that posted on project organizer. 2. Calculate descriptive statistics, i.e., mean, median and standard deviation, 3 . Estimate a regression equation for the two variables. 4. Submit a written report
Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private...
Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private data members of a UsedFurnitureItem are: age (double) // age in years – default value for brandNewPrice (double) // the original price of the item when it was brand new description (string) // a string description of the item condition (char) // condition of the item could be A, B, or C. size (double) // the size of the item in cubic inches. weight...
Consider the data contained in the Excel worksheet named Cell Phones. This data set contains monthly...
Consider the data contained in the Excel worksheet named Cell Phones. This data set contains monthly phone bills (in dollars) for a random sample of 50 cell phone users. a. Use the data set to conduct a one sample t-test to determine whether the expected bill amount equals $65 or is greater than $65. What is the p-value associated with the test? b. Construct a 95% confidence interval on expected bill amount. c. Do the data provide sufficient evidence to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT