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

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 ►
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:...
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.
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...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Do for javascript. Create a form with the following inputs. L -> Loan Amount in $'s,...
Do for javascript. Create a form with the following inputs. L -> Loan Amount in $'s, i -> Interest Rate %/year, n -> Number of Compounding Periods months Given the following formula to solve for the monthly payments mp = ( i * (1+i)^n * L ) / ( (1+i)^n - 1 ) Output the results L = $, i = %/month , n = months mp = $ And a table which lists the remaining loan amount and interest...
Write a Python script that takes an input image and output's the name of the dominant...
Write a Python script that takes an input image and output's the name of the dominant color in that image(i.e. red, green, blue).  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT