Question 3

(a) What do you mean by event in JavaScript? Give at least two examples of events with their handling.
		<html>
<head>
<script type="text/javascript">
function bgset()
{
document.getElementById('txt1').style.backgroundColor = "Yellow";
}
function bgsetb()
{
document.getElementById('btn1').style.backgroundColor = "red";
}
</script>
</head>
<body>
<form>
<input type="text" onFocus="bgset()" id="txt1" />
</form>
<button id="btn1" onClick="bgsetb()">Click Me</button>
</body>
</html>
(b) Write a JavaScript program to print first N odd numbers divisible by 7.
<html>
<body>
<script type="text/javascript">
function display()
{
var x = document.getElementById('txt1').value;
var i = 0;
for(i=0;i<=x;i++)
{
if(i%2 != 0)
{
if(i%7 == 0)
{
document.write("<br/>");
document.write(i);
}
}
}
}
</script>
</body>
<input type="text" id="txt1" />
<button onClick="display()">Display</button>
</html>
(b) Write an HTML form accepting an integer having 4-digits. Provide necessary validations using JavaScript. Input should not accept characters.
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;
if(window.event)
{
keynum = e.keyCode;
}
else if(e.which)
{
keynum = e.which;
}
if(keynum != 8)
{
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
return numcheck.test(keychar);
}
else
return keynum;
}
</script>
<form>
Type only numbers :
<input type="text" onKeyDown="return checkDigit(event)" />
</form>
</body>
</html>

Make Comments..!!


Oops!! No posts from user.

Download Android App