Write a javascript to display message ‘Exams are near, have you started preparing for?’ using alert, prompt and confirm boxes. Accept proper input from user and display messages accordingly.

 What is Javascript ?

Javascript is basically designed to create interactivity with HTML pages. It enables you to read and change the content of HTML controls and also enables you to load a specific page depending upon the client’s request. It helps you to do certain validations on client side.

What is Jquery?

jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code. jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation. 

The jQuery library contains following features: 

  • HTML/DOM manipulation 
  • CSS manipulation 
  • HTML event methods 
  • Effects and animations 
  • AJAX 
  • Utilities 


Popup boxes :

JavaScript has three kind of popup boxes: 

  • Alert box,
  • Confirm box
  • Prompt box


Q.1 ) Write a javascript to display message ‘Exams are near, have you started preparing for?’ using alert, prompt and confirm boxes. Accept proper input from user and display messages accordingly.

<html>
<body>
<h1 id="ch">Welcome</h1>
<button onclick="promptfunction()">Prompt</button> <br/> <br/>
<button onclick="confirmfunction()">Confirm</button> <br/> <br/>
<button onclick="alertfunction()">Alert</button> <br/> <br/>
<script type="text/javascript">
function promptfunction()
{
var temp = prompt('Exam are near, have you started preparing for it?
Yes or No', 'No')
if (temp === 'No')
document.getElementById('ch').innerHTML ='Start preparing for the exam'
else
document.getElementById('ch').innerHTML = 'Best of luck'
}
function confirmfunction()
{
var temp = confirm('Exam are near, have you started preparing for
it?')
if (temp == false)
document.getElementById('ch').innerHTML ='Start preparing for the exam'
else
document.getElementById('ch').innerHTML ='Best of luck'
}
function alertfunction()
{
alert('Exam are near, have you started preparing for it?')
document.getElementById('ch').innerHTML ='Start preparing for the
exam'
}
</script>
</body>
</html>

Output :



Q.2) Write a javascript function to validate username and password for a membership
form Program. (SET B)


<html>
<head>
</head>
<body>
<form name="Membership_login" onsubmit="validfunction()"
method="post">
<center>
<h3>Membership form</h3>
Username: <input type="text" name="user"></br></br>
Password: <input type="password" name="pass"></br></br>
<button type="submit" value="Login">LogIn</button>
</center>
</form>
<script type="text/javascript">
function validfunction()
{
var user = document.Membership_login.user.value
var pass = document.Membership_login.pass.value
if(user ==="rohit" && pass === "rohit123")
alert("login successful")
else if(user == null || pass=="")
alert("Empty username or password field.")
else
alert("inavlid credentials.")
}
</script>
</body>
</html>

Output :



Post a Comment

0 Comments