Example : How to change html element’s message using Java Script.
<!DOCTYPE html>
	<html>
	   <body>
		<h3>Change HTML Element's Message </h3>
		<div id="msg">HTML Elemental Message</div><br>

		<!--<input type="button" value="Show Message" onclick='document.getElementById("msg")
                        .innerHTML = "Java Script Message"'>-->
		<input type="button" value="Show Message" onclick="document.getElementById('msg')
                        .innerHTML = 'Java Script Message' ">
	   </body>
	</html>

--------------  OR  --------------
<!DOCTYPE html>
	<html>
	   <body>
		<h3>Change HTML Element's Message </h3>
		<div id="msg">The addition of two value is</div><br>		
		   
		<script>
			var a, b, c;  
			a = 5;    
			b = 6;    
			c = a + b;				
		</script>		   
<input type="button" value="Show Result" onclick="document.getElementById('msg').innerHTML = 'The additon result is = ' + c ">
	   </body>
	</html>
Example : How to display simple message on html page using Java Script.
<!DOCTYPE html>
<html>
	<head>		
		<title>Java Script Messages</title>
		<script>
			var msg = "Codershelpline";
			document.write(msg); 
		</script>
	</head>
	
	<body>		
	</body>
</html>

Output :(on HTML Page)
Codershelpline
Example : How to display simple ok-informational message using Java Script.
<!DOCTYPE html>
<html>
<head>    
    <title>JavaScript Inline Message</title>        
</head>
<body>    
    <input type="button" onclick="alert('Codershelpline')" Value="Click Me">
</body>
</html>

Output :(As PopUp Dialog)
Codershelpline

--------------  OR  ---------------
<!DOCTYPE html>
<html>
<head>    
    <title>JavaScript Inline Message</title> 
	<script>
		function msg()
		{
		   alert("Data Saved");
                   //alert(500);
                   //alert(true);
		}	
	</script>
</head>
<body>    
    <input type="button" onclick="msg();" Value="Click Me">
</body>
</html>

--------------  OR  ---------------
<!DOCTYPE html>
<html>
	<head>		
		<title>Java Script Messages</title>
		<script>
			window.onload=function() {alert("Welcome You in Codershelpline")}
			window.onunload=function() {alert("Thanks, Bye Visit Again")}
		</script>
	</head>
	
	<body>		
	</body>
</html>
Example : How to display ok-informational message in two/more lines using Java Script.
<!DOCTYPE html>
<html>
<head>    
    <title>JavaScript Inline Message</title> 
	<script>
		function msg()
		{
		   alert("Welcome\nCodershelpline Website");
		}	
	</script>
</head>
<body>    
    <input type="button" onclick="msg();" Value="Click Me">
</body>
</html>
Example : How to display ok-cancel confirmation message using Java Script.
<!DOCTYPE html>
<html>
<head>    
    <title>JavaScript Inline Message</title> 
	<script>
		function msg()
		{
		   if (confirm("Do you want to Delete the record?") == true) 
			{
                           var x = "Data deleted successfully!";
			} 
		   else 
			{
		           x = "Deletion Cancelled";
			}				
			alert(x);
		}	
	</script>
</head>
<body>    
    <input type="button" onclick="msg();" Value="Click Me">
</body>
</html>

--------------  OR  ---------------
<html>
   <head>   
      <script>         
            function msg() 
	    {
               var x = confirm("Do you want to Delete the record ?");
               if( x == true )   // OR if(x)
	          {
                  document.write ("User wants to Delete the record!");
                  return true;
                  } 
	       else 
	          {
                  document.write ("User does not want to Delete the record!");
                  return false;
                  }
            }        
      </script>     
   </head>
   
   <body>           
      <form>
         <input type = "button" value = "Click Me" onclick = "msg();">
      </form>      
   </body>
</html>
Example : How to input data by the user as input box using Java Script.
<!DOCTYPE html>
<html>
<head>    
    <title>JavaScript Inline Message</title> 
	<script>
		function msg()
		{
			var x=prompt("Enter your name");
			//var x=prompt("Enter your name","Put your name here");
			if (x == null || x == "") 
				{
				  y = "User not entered the name";
				} 
			else 
				{
				  y = "Welcome " + x + " as JS message";
				}
			alert(y);
		}	
	</script>
</head>
<body>    
    <input type="button" onclick="msg();" Value="Click Me">
</body>
</html>

 2,419 total views,  8 views today


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.