GTU WTAD Practical 3 : Create a Form in HTML with two fields, minimum and maximum, write JavaScript to validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum

GTU WTAD Practical 3 : Create a Form in HTML with two fields, minimum and maximum, write JavaScript to validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum.

GTU WTAD Practical 3

In this example user will enter number1 and number2 in the appropriate textbox, using JavaScript code i will check out that which number is maximum and which one is minimum and will display message to the user.

Jump to GTU WTAD Practical 4.

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu03\

<html>
<head>
	<title> GTU WTAD Practical 3 : Create a Form in HTML with two fields, minimum and maximum, write JavaScript to validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum </title>

	<script language="javascript">

		
		function gtu_prog3()
		{
			minno=form1.min.value;
			maxno=form1.max.value;
			
			if(isNaN(minno))
				alert("Invalid Number 1");
			else if(isNaN(maxno))
				alert("Invalid Number 2");
			else
			{
				if(minno<maxno)
					alert("Congratulations... Its Valid Number");
				else
					alert("Take care");
			}
		}	

	</script>
</head>
<body>
	<center> <h2> GTU WTAD Practical 3 : Create a Form in HTML with two fields, minimum and maximum, write JavaScript to 
validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum. </h2></center>
	<script language="javascript">
		//gtu_prog3()
	</script>
	
	<form name="form1">
	<table cellspacing="10">
	<tr>
		<td>
			<b>Enter Number 1(Minimum) :</b>
		</td>
		<td>
			<input type="text" name="min" size=10>
		</td>
	</tr>
	<tr>
		<td>
			<b>Enter Number 2(Maximum) :</b>
		</td>
		<td>
			<input type="text" name="max" size=10>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="button" value="Submit" onClick="gtu_prog3()">
		</td>
	</tr>
	</table>
		
	</form>

</body>
</html>

 

output

GTU WTAD Practical 3

 

JavaScript Conversion functions.

  • Number() : this method is used to convert data into Number
  • parsetInt() : this method is used to convert data into integer type of number
  • parseFloat() : this method is used to convert data into Float type of number.
  • valueOf() : this method is used to convert string to number.

 

How to Generate Random Number between 0 to 99 in JavaScript ?

Math.random() * 100;

 

How to create Date Variable in JavaScript ?

In JavaScript date is calculated in miliseconds, but you can use following constructor to create date object. be sure to assign month -1 as month is value is considered as index value (possible values : 0 – 11)

<script>
   var mydt = new Date(2015,0,13);
   document.write(mydt);
   //Tue Jan 13 2015 00:00:00 GMT+0530 (India Standard Time)
</script>

 

How to extract day, month, year, hour, minute and second from data using JavaScript ?

<script>
   var mydt = new Date(2015,0,13,10,11,12);
   document.write(mydt.getDate());         // 13
   document.write(mydt.getMonth());        // 0 (be sure about this)
   document.write(mydt.getFullYear());     // 2015
   document.write(mydt.getHours());        // 10
   document.write(mydt.getMinutes());      // 11
   document.write(mydt.getSeconds());      // 12
</script>

Leave a Reply