JavaScript

http://govindasuccess.blogspot.in

Govind Marriage website : http://govindtanu.blogspot.com 

Java Script Programs....!

1) Simpledemo.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo of javascript--http://govindasuccess.blogspot.in</title>
</head>
<body>
<abbr>hello </abbr>
<script language="javascript">
alert(" http://govindasuccess.blogspot.in ");
document.write("<br> http://govindasuccess.blogspot.in ");
</script>
</body>
</html>

2) Display value using external Files

demo.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo of External java script--http://govindasuccess.blogspot.in </title>
<script src="f1.js"></script>
</head>
<body>
<form name="f1">
Enter your name:- <input type="text" name="name" /><br />
Enter your Last Name:- <input type="text" name="lname" /><br />
Enter Address <textarea name="add" rows="3" cols="2"></textarea><br />
Enter contact no :-<input type="text" name="cnt"  />
<input type="button" name="submit" value="Submit" onclick="hello();" />
</form>
</body>
</html>

f1.js

function hello()
{
 var name=f1.name.value;
 var lname=f1.lname.value;
 var add=f1.add.value;
 var cnt=f1.cnt.value;

 document.write("<br> Your Name is :-",name);
 document.write("<br> Your Last Name is:-",lname);
 document.write("<br> Your Address is:-",add);
 document.write("<br> Your Contact no is:-",cnt);
document.write("<br> http://govindasuccess.blogspot.in");

}

2-A) Types of On click Event...! 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Java Script with Message Box</title>
<script type="text/javascript">
alert('Hey, remember to tell your friends govindasuccess.blogspot.com');
alert('nice');
</script>
</head>
<body>
<input type="button" onclick="alert('Hey, remember to tell your friends govindasuccess.blogspot.com');" value="Alert" />
<hr />
<input type="button" onDblClick="alert('Hey, remember what I said!');" value="Double Click Me alert!" />
<hr />
<input type="button" onclick="confirm('Are you sure you want to delete the Internet?');" value="Confirm" />
<hr />
<input type="button" onclick="prompt('Please enter your favorite website', 'google.com');" value="Prompt" />
</body>
</html>


3) Check Box with Java Script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check Box with Java Script</title>
 <script type="text/javascript">
 var checkflag = "false";

  function check(field) {
    if (checkflag == "false") {
      for (i = 0; i < field.length; i++) {
         field[i].checked = true;
         }
    checkflag = "true";
    return "Uncheck All";
  } else {
    for (i = 0; i < field.length; i++) {
      field[i].checked = false;
    }
    checkflag = "false";
    return "Check All";
  }
}
</script>
</head>
<body>
    <form name=myform action="#" method=post>
<table>
  <tr><td>
    <strong>Make a selection</strong><br>
    <input type=checkbox name=list value="1">Java<br>
    <input type=checkbox name=list value="2">JavaScript<br>
    <input type=checkbox name=list value="3">ASP<br>
    <input type=checkbox name=list value="4">HTML<br>
    <input type=checkbox name=list value="5">SQL<br>
    <br>                                                   
    <input type=button value="Check All" onClick="this.value=check(this.form.list)">
  </td></tr>
</table>
</form>
</body></html>

4) Use of function..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Java Script Function</title>
<script type="text/javascript">
<!--
function displayMessage(firstName,lastname) {
    alert("Your Name is :- " + firstName + " " +lastname+ " ")
}
//-->
</script>
</head>
<body>
<form>
<h1>http://govindasuccess.blogspot.in</h1>
First name:<input type="input" name="yourName" />
Last Name:<input type="input" name="lastname" />
<input type="button" onclick="displayMessage(form.yourName.value,lastname.value)"
  value="Display Message" />
 </form>
</body>
</html>

4.1) Use of function.for the Patternts.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Use of function.for the Patternts</title>
</head>
<body>
<h1>Use of Nested For Loop with Text Box in Java script</h1>
<script language="javascript">
function display()
{
 var i,j,n;
 n=f1.t1.value;
 for(i=0;i<=n;i++)
 {
  for(j=1;j<=i;j++)
  {
  document.write(" * ");
  }
  document.write("<br>");
 }
}
</script>
<form name="f1">
Enter Any Value:-<input type="text" name="t1" />
<input type="button" value="click me" onclick="display()" />
</form>
</body>
</html>

5) Getting text using prompt.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript getting text--http://govindasuccess.blogspot.in/ </title>
<script language="javascript" type="text/javascript" >
<!-- hide me
var hello="My first Variable in java script click for more codes of java script http://govindasuccess.blogspot.in/";
document.write(hello);
var firstName = prompt("http://govindasuccess.blogspot.in..What's your first name?", "");
document.write("<br>",firstName);
var a=prompt("Enter value A", "");
// end hide -->
</script>
</head>
<body>
<input type="button" value="Click me" >
</body>
</html>

6) Table using javascript...!
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create table using java script-- http://govindasuccess.blogspot.in</title>
<script language="javascript">
function table()
{
var m;
m=window.open("");
m.document.write("<table border=2>");
m.document.write("<tr>");
m.document.write("<td>Name</td>");
m.document.write("<td>Birth Date</td>");
m.document.write("</tr>");
m.document.write("<tr>");
m.document.write("<td>");
m.document.write(f1.name.value);
m.document.write("</td>");
m.document.write("<td>");
m.document.write(f1.dob.value);
m.document.write("</td>");
m.document.write("</tr>");
m.document.write("</table>");
}
</script>
</head>
<body>
<form name="f1">
<h1>Demo of Table Using Javascript</h1>
Enter Your Name:<input type="text" name="name"  />
Enter Your Date of Birth:<input type="text" name="dob" />
<input type="button" value="Save" onclick="table();" />
</form>
</body>
</html>

7) Javascript Validation Form....!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Java Script validati Registration form.. http://govindasuccess.blogspot.in. </title>
<script type="text/javascript">
function validateForm()
{
var em=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var email=document.forms["f1"]["email"].value;
var letters= /^[A-Za-z]+$/;
var fname=document.forms["f1"]["fname"].value;
var pass=document.forms["f1"]["pass"].value;
var cpass=document.forms["f1"]["cpass"].value

 if ((document.forms["f1"]["fname"].value=="") ||(document.forms["f1"]["fname"].value==null))
  {
  alert("First name must be filled out");
  document.f1.fname.focus() ;
     return (false);
  }
   if (!fname.match(letters))
  {
  alert("Only letters are allowed...!");
  document.f1.fname.focus() ;
     return (false);
  }
  if ((document.forms["f1"]["lname"].value=="") || (document.forms["f1"]["lname"].value==null))
  {
  alert("Username Must be filed out");
  document.f1.lname.focus() ;
     return(false);
  }
  if ((document.forms["f1"]["pass"].value=="") || (document.forms["f1"]["pass"].value==null))
  {
  alert("Password Must be filed out");
  document.f1.pass.focus() ;
     return(false);
  }
   if ((document.forms["f1"]["cpass"].value=="") || (document.forms["f1"]["cpass"].value==null))
  {
  alert("Conform Password Must be filed out");
  document.f1.cpass.focus() ;
     return(false);
  }

   if (pass!=cpass)
  {
  alert("Password Are Not Macth");
  document.f1.cpass.focus() ;
     return(false);
  }
  else
  {
  if(cpass!=pass)
  {
  alert("Password  Not Macth");
  document.f1.pass.focus() ;
      return(false);
}
  }
  if ((document.forms["f1"]["add"].value=="") || (document.forms["f1"]["add"].value==null))
  {
  alert("Address must be Filed out");
  document.f1.add.focus() ;
     return(false);
  }
    if ((document.forms["f1"]["email"].value=="") || (document.forms["f1"]["email"].value==null))
  {
  alert("Email must be Filed out");
  document.f1.email.focus() ;
     return(false);
  }
    if (em.test(email)==false)
  {
  alert("Invalid Email id...!");
  document.f1.email.focus() ;
     return(false);
  }
  if (document.forms["f1"]["country"].value=="Select country")
  {
  alert("Country is not Selected...!");
  document.f1.country.focus() ;
     return(false);
  }
  if (document.forms["f1"]["state"].value=="Select state")
  {
  alert("state is not Selected...!");
  document.f1.state.focus() ;
     return(false);
  }
   if (do
 
   cument.forms["f1"]["city"].value=="Select City")
  {
  alert("city is not Selected...!");
  document.f1.city.focus() ;
     return(false);
  }
  if ( (gender[0].checked == false ) && ( gender[1].checked == false ) )
  {
   alert("Select Gender Male or Female...!");
     return(false);
  }
  if(document.forms["f1"]["upload"].value=="")
  {
  alert("Select file for uploading...!");
  document.f1.upload.focus();
     return(false);
  }
  return(true);
}
</script>
</head>

<body>

<form name="f1" action="thankyou.html" onsubmit="return (validateForm());" method="post">
<h1>Demo of Registration page with Javascript Validation.....http://govindasuccess.blogspot.in </h1>
<table border="1" align="center">
<tr>
<td>First name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Username:-</td><td><input type="text" name="lname"></td></tr>
<tr><td>Password:-</td><td><input type="password" name="pass"></td></tr>
<tr><td>Conform Password:-</td><td><input type="password" name="cpass"></td></tr>
<tr><td>Address:-</td><td><textarea name="add" rows="5" cols="10"></textarea></td></tr>
<tr><td>Email id:-</td><td><input type="text" name="email" /></td></tr>
<tr><td>Country:-</td><td><select name="country" style="width:120px;"><option>Select country</option><option>India</option><option>America</option></select></td></tr>
<tr><td>State:-</td><td><select name="state" style="width:120px;"><option>Select state</option><option>Gujarat</option><option>Sabarkantha</option></select></td></tr>

<tr><td>City:-</td><td><select name="city" style="width:120px;"><option>Select City</option><option>Ahmedabad</option><option>Baroda</option></select></td></tr>
<tr><td>Gender:-</td><td><input type="radio" name="g1"  id="gender" value="Male" />Male<input type="radio" name="g1" id="gender" value="Female"  />Female</td></tr>
<tr><td>Upload File :</td><td><input type="file" name="upload" /></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit"></td></tr>
</table>
</form>
</body>

</html>

1 comment:

Akshay Deep said...

Sir

I am also a Computer Engg.I liked your scripts.
I am also intrested in Programming