Assignment:: 1: 1) .Write A Program To Embed Javascript Into HTML
Assignment:: 1: 1) .Write A Program To Embed Javascript Into HTML
Assignment :: 2
2).Write a JavaScript code to demonstrate Conditional Statements.
<html>
<body>
<script language="javascript">
var result,n;
result=parseInt(prompt("Enter A Number"));
if(result >=35)
document.write("Pass");
else
document.write("Fail");
</script>
</body>
</html>
Assignment :: 3
3).Write a JavaScript code to Demonstrate Looping Statements.
For Loop
<html>
<body>
<script language="javascript">
var i;
for(i=1;i<=10;i++)
{
document.write(i+"<br>");
}
</script>
</body>
</html>
While Loop
<html>
<body>
<script language="javascript">
var i;
i=1;
while(i<=10)
{
document.write(i+"<br>");
i=i+1;
}
</script>
</body>
</html>
Assignment :: 4
4).Write JavaScript code to demonstrate Different String Function.
<html>
<body>
<script language="javascript">
var x="INDIA";
document.write(x.charAt(2));
document.write("\n"+x.charCodeAt(3));
var a="Hello";
var b="Friends";
document.write("\n"+a.concat(b));
var c="green";
document.write("\n"+c.replace("een","ay"));
document.write("\n"+x.toLowerCase());
document.write("\n"+c.toUpperCase());
document.write("\n"+x.indexOf('D'));
document.write("\n"+x.lastIndexOf("I"));
document.write("\n"+a.slice(0,3));
</script>
</body>
</html>
Assignment :: 5
5).Write JavaScript code to demonstrate onblur,onfocus,onload,onsubmit.
Onblur & Onfocus Event
<html> </script>
<body> </body>
<h1>HTML DOM Events</h1> </html>
<h2>The onfocus and blur Onsubmit Event
Events</h2>
<html>
<p>When you enter the input field,a
function sets <body>
{ }
</script>
</body>
document.getElementById("myInput").style.b
ackground="red"; </html>
}
Assignment :: 6
6).Write
<html>
JavaScript code to demonstrate onkeypress,
{
onmouseove ,onmouseout.
<body> alert("This is JavaTpoint");
//onkeypress
<h1>HTML DOM Events</h1> }
Assignment :: 7
7).Write a programto perform addition of two numbers using web form.
<html>
<head>
<script>
function add()
{
var numOne, numTwo, sum;
numOne = parseInt(document.getElementById("first").value);
numTwo = parseInt(document.getElementById("second").value);
sum = numOne + numTwo;
document.getElementById("answer").value = sum;
}
</script>
</head>
<body>
<p>Enter the First Number: <input id="first"></p>
<p>Enter the Second Number: <input id="second"></p>
<button onclick="add()">Add</button>
<p>Sum = <input id="answer"></p>
</body>
</html>
Assignment :: 8
8).Create a HTML page to demonstrate Date object using web form.
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>Create a new date object with the current date and time:</p>
<p id="demo"></p>
<script>
const d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>
Assignment :: 9
9).Write a Javascript code to demonstrate use of Dialog Box.
//Alert Dialog Box <script type="text/javascript">
<html> function show() {
<head> alert("It is an Alert dialog box");
} }
</script> </script> </head>
</head> <body> <center>
<body> <h1>Hello World :) :)</h1>
<center> <h2>Welcome to javaTpoint</h2>
<h1>Hello World :) :)</h1> <p>Click the following button </p>
<h2>Welcome to javaTpoint</h2> <input type="button" value="Click Me"
onclick="show();" />
<p>Click the following button </p>
</center> </body> </html>
<input type="button" value="Click Me"
onclick="show();" /> // Prompt Dialog Box
</center> <html> <head>
</body> <script type="text/javascript">
</html> function show() {
// Confirm Dialog Box var value = prompt("Enter your Name : ",
"Enter your name");
<html>
document.write("Your Name is : " + value);
<head>
}
<script type="text/javascript">
</script> </head>
function show() {
<body> <center>
var con = confirm ("It is a Confirm dialog
box"); <h1>Hello World :) :)</h1>
if(con == true) { <h2>Welcome to javaTpoint</h2>
document.write ("User Want to continue"); <p>Click the following button </p>
} <input type="button" value="Click Me"
onclick="show();" />
else {
</center>
document.write ("User does not want to
continue"); </body>
} </html>
Assignment :: 10
10).Write a Javascript to apply form validation-not null,number,string.
//Number Validation var
num=document.myform.num.value;
<script>
if (isNaN(num)) {
function validate(){
document.getElementById("numloc" validateForm()" method="post"
).innerHTML="Enter Numeric value required>
only";
Name: <input type="text"
return false; name="fname">
</form>