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 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.
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 =...
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...
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...
Palindrome Javascript I am trying to write this javascript function to check if a number is...
Palindrome Javascript I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. This is the code i have, but it doesnt work. Code: let convertButton = document.getElementsByClassName("btn")[0]; let userInput = document.getElementById("number").value; let results = document.getElementById("result").value; convertButton.addEventListener("click", function (event) { event.preventDefault(); console.log(userInput); if (validatePalidrome(userInput)) document.getElementById("result").innerHTML = "true"; else document.getElementById("result").innerHTML = "false"; }); function validatePalidrome(numbers) { let...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., 12321 This is the code i have, but it doesnt work. PLEASE MAKE SURE IT WORK BEFORE POST ANSWER, I GOT @ CODE THAT DID WORK BEFORE HTML JavaScript Palindrome Exercise rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" /> Palindrome Enter a positive number: Is this a palindrome? No...
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...
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...
Write in javaScript: User input 5 words in one input, and print out the longest word.
Write in javaScript: User input 5 words in one input, and print out the longest word.
Create an HTML form with the following: 2 text input fields 1 text area 2 radio...
Create an HTML form with the following: 2 text input fields 1 text area 2 radio buttons or 3 checkboxes 1 button Include labels for fields
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT