Space for google add

JavaScript code using alert box and different formatting styles.

 


1. Write a javascript to display message ‘Good Morning’ using alert box


Programme:-

<html>

<script>

window.alert("Good Morning");

</script>

</html>


2. Write a javascript function to validate username and password for a

membership form.


Programme:-

<html>

<body>  

<form name="f1" onsubmit="validateform()" >  

Username: <input type="text" name="name"><br/>  

Password: <input type="password" name="password"><br/>  

Re-enter Password:<input type="password" name="password2"/><br/>  

<input type="submit" value="Submit">  

</form>  

</body>

<script>

function validateform()

{  

var name=document.f1.name.value;  

var password =document.f1.password.value;  

var password1 =document.f1.password2.value;  

  

if (name==null || name=="")

{  

  alert("Name can't be blank");  

}

else if(password.length<6)

{  

          alert("Password must be at least 6 characters long.");  

 

else if(password == password1)

{

  alert("You logged in successfully.");

}

else

{  

  alert("password must be same!");  

}  

}  

</script> 

</html>


3. Using Javascript function, display the string in different formatting

styles(Bold, italic, underline, strikethrough, hypertext etc)


Programme:-

<html>

<body>

<script>

var txt = "Avdhoot Navnath Avhad";

document.write("The original string: " + txt);

document.write("<p>Big: " + txt.big() + "</p>");

document.write("<p>Small: " + txt.small() + "</p>");


document.write("<p>Bold: " + txt.bold() + "</p>");

document.write("<p>Italic: " + txt.italics() + "</p>");


document.write("<p>Fixed: " + txt.fixed() + "</p>");

document.write("<p>Strike: " + txt.strike() + "</p>");


document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>");

document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>");


document.write("<p>Subscript: " + txt.sub() + "</p>");

document.write("<p>Superscript: " + txt.sup() + "</p>");


document.write("<p>Link: " + txt.link("https://www.drdo.gov.in") + "</p>");

document.write("<p>Blink: " + txt.blink());


//document.write("<p>Underline:" + txt.underline());

//document.write("<p>Hypertext: " + txt.hypertext());

</script>

</body>

</html>

4. Write a Javascript to create a FIFO queue . Insert new element in it

(Hint: Use concept of Array )


Programme:-

<html>

<script>

var a=[45,78,96,52];

document.writeln(a,"<br>");

document.writeln("Insert element in queue.<br>");

var value=prompt("Enter number :");

var b =a.unshift(value);

document.writeln("No of elements in array :",b);

document.writeln("<br>",a);

</script>

</html>



Post a Comment

0 Comments