Question

In: Computer Science

Write a JavaScript function to get the values of form containing the following input fields: fname...

Write a JavaScript function to get the values of form containing the following input fields:

  • fname

  • lname

  • address

  • city

  • state

Solutions

Expert Solution

CODE

<!DOCTYPE html>
<html>
<head>
<script>
function getValues() {
    var result = "";
result += "First Name: " + document.forms["myForm"]["fname"].value + "<br>";
result += "Last Name: " + document.forms["myForm"]["lname"].value + "<br>";
result += "Address: " + document.forms["myForm"]["address"].value + "<br>";
result += "City: " + document.forms["myForm"]["city"].value + "<br>";
result += "State: " + document.forms["myForm"]["state"].value + "<br>";

document.getElementById("output").innerHTML = result;
}
</script>
</head>
<body>

<form name="myForm" onsubmit="return false">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
Address: <input type="text" name="address"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
<button type"button" onclick="getValues()">Submit</button><br>
</form>

<hr>
<div>
<p id="output" />
</div>
</body>
</html>


Related Solutions

Write a function getStats(fname) that determines the following statistics for the input file, fname, and write...
Write a function getStats(fname) that determines the following statistics for the input file, fname, and write the results to the text file, FileStats.txt. • Number of occurrences of each day of the week in the file. • Number of lines (determined by end of line character “\n”) • Number of words • Numbers of characters (excludes spaces between words) The output from getStats() should • print the message ‘To view the results go to FileStats.txt’ • return ‘Thanks for using...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using a NumericUpDown. Have the function calculate the surface area and display it on your page. Label the inputs and the output on your page. Change the title to "Oh, Boy! JavaScript!". Put your name at the top in camelCase. Put your major at the bottom in camelCase.
Write a function cube_all_lc(values) that takes as input a list of numbers called values, and that...
Write a function cube_all_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the numbers in values (i.e., the numbers raised to the third power). This version of the function may not use recursion.
Get values for min and max using assignment statements and the input function. Print min and...
Get values for min and max using assignment statements and the input function. Print min and max. Run the script. fix any errors you find. Remove the print statements you wrote above. Print the labels "Kelvin" and "Fahrenheit". Print a line of dashes under the labels. Run the script. fix any errors you find. Write a for loop that will give the loop variable kelvin values between min and max. Inside the code block print the value of kelvin Run...
log in form Requirements: Form: There should be at least 2 input fields for username and...
log in form Requirements: Form: There should be at least 2 input fields for username and password. Use an array as a database in which there are several usernames and passwords: Usernames can be either emails or nick names (WITHOUT WHITE SPACE) After the user submitted the form, students must: sanitize the inputs check if there is a match with one username and one password in the array. If there is no match, print out an error message to user...
Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
Create a JavaScript function that will collect the information from the form and verify that it...
Create a JavaScript function that will collect the information from the form and verify that it is the correct type and that there are no blank textboxes. Save and test the file to ensure that the textbox information is collected and the script is working correctly. Use the onclick event within the submit button to call this function. Output validation error messages by writing directly to the with the id of "results." (You may want to use alert boxes for...
1.) Write a function, base2tobase10 that has a single input, a vector containing 1,s and 0...
1.) Write a function, base2tobase10 that has a single input, a vector containing 1,s and 0 's representing a binary number. For example the binary number 01101011 would be represented by the vector [ 0, 1, 1, 0, 1, 0,1, 1]. Your function should return a single output,the base 10 equivalent of the base 2 number. First, your function must check the input vector and detremine if any of the vector elemnets are not a 0 or a1. If they...
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter...
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter username:") A: What is your name? B: My name is XXXX. B: What is yours? A: My name is XXXX. A: Nice to meet you. B: Nice to meet you, too. Use print statement and use input() function
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list...
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the even numbers in values (i.e., the even numbers raised to the third power). For example: >>> cube_evens_lc([2, 5, 6, 4, 1]) result: [8, 216, 64] This version of the function may not use recursion. Write a function cube_evens_rec(values) that takes as input a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT