Question

In: Computer Science

Create a form with two inputs name and roll number.And write a script to validate the...

Create a form with two inputs name and roll number.And write a script to validate the inputs.Any of them should not be empty.
Name will be string and roll number will be number between 1 -10 only

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new web page with name "validationScript.html" is created, which contains following code.

validationScript.html :

<!DOCTYPE html>

<html lang="en">

<head>

<!-- title for web pages -->

<title>Validation Script</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<form onsubmit="return validateInput()">

Name :

<!-- textbox for name -->

<input type="text" id="txtName"/>

<br><br>

Roll Number :

<!-- textbox for rollnumber -->

<input type="text" id="txtRollNumber"/>

<br><br>

<!-- button to submit form -->

<input type="submit"/>

</form>

<!-- <script> is used for javascript -->

<script>

function validateInput()

{

//taking name entered by user

var name=document.getElementById("txtName").value;

var rollNumber=document.getElementById("txtRollNumber").value;

//regular expresiion for name that allows string only

var nameExp = /^[a-zA-Z ]+$/;

//checking inputs

if(name=="")

{

//if name is empty

alert("Enter Name");

return false;//not allow to submit form

}

else if(rollNumber=="")

{

//if roll number is empty

alert("Enter Roll Number");

return false;//not allow to submit form

}

else if(parseInt(rollNumber)<=1 || parseInt(rollNumber) >=10)

{

//if roll number is not in between 1 to 10 then

alert("Enter Roll Number between 1 to 10");

return false;//not allow to submit form

}

else if(!name.match(nameExp))

{

//if name does not contains letters

alert("Name should contains letters only");

return false;//not allow to submit form

}

else{

//when all validations passed

alert("Validations Passed.Submit form");

return true;

}

}

</script>

</body>

</html>

======================================================

Output : Open web page validationScript.html in the browser and will get the screen as shown below

Screen 1 :validationScript.html

Screen 2:Screen when name is empty

Screen 3:Screen when roll number is empty

Screen 4:Screen when roll number is not between 1 to 10

Screen 5:Screen when name contains numbers

Screen 6:Screen when all validation passed

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Create a webpage with HTML and JAVA Script that takes a user's 4 inputs (first name,...
Create a webpage with HTML and JAVA Script that takes a user's 4 inputs (first name, last name, phone number, and sex[using checkbox, must set on load and change whenever the checkbox is selected, only 1 box can be selected, selecting the other automatically deselects the latter]) The first button saves all the inputs into LOCAL STORAGE The Second button retrieves all the data in LOCAL STORAGE and displays them on the same page. Alert box to inform the user...
Write a Program for Examination depart of your college. Program should take these inputs Name, Roll...
Write a Program for Examination depart of your college. Program should take these inputs Name, Roll No, Faculty, and All 4 Subjects Marks. After that Clear the Console Screen & Print an eye-catching Mark sheet. This is showing Name, Roll No, Faculty, All 4 Subjects Marks, Total Marks, Percentage, Grade and Remarks. Follow below criteria for Grade & Remarks Percentage Grade Remarks >= 87 A Excellent 78 - 86 B+ Good 72 – 77 B Good 66 – 71 C+...
QUESTION: Write regular expressions after the ► to validate the following inputs: a) Product codes that...
QUESTION: Write regular expressions after the ► to validate the following inputs: a) Product codes that have one or more letters followed by one or more digits. ► b) Nonnegative integers between 1,000 and 9,999, including the comma. ► c) Canadian zip code containing upper case characters only. ► d) License plate numbers that have the form:          Letter          Digit          Letter          Hypen (-)          Digit          Letter          Digit ►
Create, test, and validate an HTML document that has a form with the following controls: a....
Create, test, and validate an HTML document that has a form with the following controls: a. A text box to collect the user's name b. Four checkboxes, one for each of the following items: i. Four 25-watt light bulbs for $2.39 ii. Eight 25-watt light bulbs for $4.29 iii. Four 25-watt long-life light bulbs for $3.95 iv. Eight 25-watt long-life light bulbs for $7.49 c. A collection of three radio buttons that are labeled as follows: i. Visa ii. Master...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Utilizing PHP and HTML code Create a form that has text inputs for two numbers and...
Utilizing PHP and HTML code Create a form that has text inputs for two numbers and a submit button. Submit the values to a program that calculates and displays the GCD of the two numbers. The greatest common divisor of two integers a and b is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and 0 is that number. For example:...
ASSIGNMENT: Write a program to ask for the name and test score for 8 students, validate...
ASSIGNMENT: Write a program to ask for the name and test score for 8 students, validate that the test score is between 0.0 and 100.0 inclusive, and store the names and test scores in 2 parallel arrays. Then, calculate and display the average of the test scores. Finally, display all the students who have test scores above the average. Example Run #1: (bold type is what is entered by the user) Enter student name #1: George Enter the score for...
Write down the regression model form with two quantitative inputs and one qualitative input with three...
Write down the regression model form with two quantitative inputs and one qualitative input with three discrete levels. For each discrete level, we wish to have a complete second order model of the quantitative variables.
Create, test, and validate an HTML document for yourself, including your name, address, and email address....
Create, test, and validate an HTML document for yourself, including your name, address, and email address. If you are a student, you must include your major and your grade level. This document must use several headings and <em>, <strong>, <hr />, <p>, and <br /> tags.
Write a bash script that will allow you to: Read in your Your name Course name...
Write a bash script that will allow you to: Read in your Your name Course name and Instructor’s name Then prompt the user to enter two numbers and determine which number is greater. Ex: If 10 is entered for the first number and 3 for the second, you should output Your name Course name Instructor’s name 10 is greater than 3. If 33 is entered for the first number and 100 for the second, you shou output Your name Course...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT