Monday 1 April 2013

Simple HTML form with JavaScript alert Validation

<html>
<head>
<title>Welcome form</title>
<script type="text/javascript">

function validateForm()
{
var a=document.forms["Amanforms"]["firstname"].value;
if(a==null || a=="")
 {
  alert("Please fill the first name...");
  return false;
 }
var b=document.forms["Amanforms"]["lastname"].value;
if(b==null || b=="")
 {
  alert("Please fill the last name...");
  return false;
 }
var c=document.forms["Amanforms"]["password"].value
if(c==null || c=="")
 {
  alert("Please fill the password...");
  return false;
 }
var d=document.forms["Amanforms"]["address"].value
if(d==null || d=="")
 {
  alert("please fill the address...");
  return false;
 }
var e=document.forms["Amanforms"]["phone"].value
if(e==null || e=="")
 {
 alert("Please fill the phone number...");
 return false;
 }
var f=document.forms["Amanforms"]["mobile"].value
if(f==null || f=="")
 {
  alert("Please fill the mobile number...");
  return false;
 }
}

</script>
</head>
<body>
<form action="test.html" method="post" name="Amanforms"
onsubmit="return validateForm()"
>
<table align="center">
<img
src="C:\Documents and Settings\Tarun\My Documents\My Pictures\corporate.jpg"
alt="corporate.jpeg"
/>
<tr>
<td><b>First name:</b>
</td>
<td><input type="text" name="firstname" />
</td>
</tr>
<tr>
<td><b>Last name:</b>
</td>
<td><input type="text" name="lastname" />
</td>
</tr>
<tr>
<td><b>password:</b>
</td>
<td><input type="password" name="password" />
</td>
</tr>
<tr>
<td><b>Address:</b>
</td>
<td><input type="text" name="address" />
</td>
</tr>
<tr>
<td><b>Phone no:</b>
</td>
<td><input type="Digit" name="phone" />
</td>
</tr>
<tr>
<td><b>Mobile no:</b>
</td>
<td><input type=" Digit" name="Mobile" />
</td>
</tr>
<tr>
<td><button type="submit">submit</button>
</td>
<td><button type="cancle">cancle</button>
</td>
</tr>
</table>
</form>
</body>
</html>

JavaScript HTML Validation Forms with CSS

<!-- Copy this code and save "file.html" and use it -->

<html>
<font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">
<head>
<!--start head-->
<title>CSS Form Validation</title>
<style type="text/css">
.error {
color: #FF0000;
}

span {
font-weight: bold;
}
</style>


<SCRIPT language=JavaScript>
<!--
//Any fields that are left empty, or are not properly filled in, will be highlighted in red. //Fields that are filled in correctly will be properly formatted.

function validate() {

if (!document.getElementById)
return;

// get form variables

var title = document.getElementById("title").value;

var firstname = document.getElementById("firstname").value;

var lastname = document.getElementById("lastname").value;

var address1 = document.getElementById("address1").value;

var address2 = document.getElementById("address2").value;

var city = document.getElementById("city").value;

var state = document.getElementById("state").value;

var zipcode = document.getElementById("zipcode").value;

var phone = document.getElementById("phone").value;
         
var fax = document.getElementById("fax").value;

var incorrect = new Array();

var no = 0;

var regExp = /[A-Za-z]{2,6}/;

if (regExp.test(title)) {

title = title.charAt(0).toUpperCase()
+ title.substring(1, title.length).toLowerCase();

} else {

incorrect[no] = "1";

no++;

title = "";

}

regExp = /[A-Za-z]{1,}/;

if (regExp.test(firstname)) {

firstname = firstname.toUpperCase();

} else {

incorrect[no] = "2";

no++;

firstname = "";

}

regExp = /[A-Za-z]{3,}-?[A-Za-z]?/;

if (regExp.test(lastname)) {

lastname = lastname.charAt(0).toUpperCase()
+ lastname.substring(1, lastname.length).toLowerCase();

} else {

incorrect[no] = "3";

no++;

lastname = "";

}

if (address1.length < 5) {

incorrect[no] = "4";

no++;

address1 = "";

}

if (address2.length < 3) {

incorrect[no] = "5";

no++;

address2 = "";

}

if (city.length < 3) {

incorrect[no] = "6";

no++;

city = "";

}

if (state.length < 5) {

incorrect[no] = "7";

no++;

state = "";

}

if (zipcode.length < 5) {

incorrect[no] = "8";

no++;

zipcode = "";

}

if (phone.length < 7) {

incorrect[no] = "9";

no++;

phone = "";

}

if (fax.length < 7) {

incorrect[no] = "8";

no++;

fax = "";

}

for (i = 1; i < 11; i++) {

document.getElementById(i).style.color = "#000000";

}

for (j = 0; j < no; j++) {

document.getElementById(incorrect[j]).style.color = "#FF0000";

}

if (no > 0) {

document.getElementById("errors").innerHTML = "<span class=\"error\">There was an error with your form submission. Please fill in the necessary fields.</span><br />";

}

document.getElementById("title").value = title;

document.getElementById("firstname").value = firstname;

document.getElementById("lastname").value = lastname;

document.getElementById("address1").value = address1;

document.getElementById("address2").value = address2;

document.getElementById("city").value = city;

document.getElementById("state").value = state;

document.getElementById("zipcode").value = zipcode;

document.getElementById("phone").value = phone;
     
document.getElementById("fax").value = fax;

}
//-->
</SCRIPT>

<script  language=JavaScript>

function upperCase(id)
{
id.value = id.value.toUpperCase();
}

</script>



<!--end head-->
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF"alink="#FF0000">
<font size="2" color="#000000" face="Arial">
<div align="center">
&nbsp;
</style>
</div>
</td>
<td valign="middle">
<div align="right">
<!-- AddThis Button BEGIN -->
&nbsp;
<script type="text/javascript">
var addthis_pub = 'gloryless';
</script>
<!-- AddThis Button END -->
</div>
</td>
</tr>
</table>
</div>
<table width="950" border="0" cellpadding="5" cellspacing="0">
<tr valign="top">
<td colspan="2"><div align="center">
<script type="text/javascript">
</script>
</div>
</td>
</tr>
<tr valign="top">
<td width="10%" bgcolor="#c5c3c4" align="left">
<table border="0" width=122>
<br />
</td>
<td><center>
<br />
<br />
<div align="center">
<div id="details" align="center">
<div id="errors"></div>
<form action="" method="post">
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td align="right"><span id="1">Title </span>
</td>
<td><input name="id" id="title" onkeyup="upperCase(this)" type="text" size="25"
maxlength="6"
></td>
</tr>
<tr>
<td align="right"><span id="2">First Name </span>
</td>
<td><input name="firstname" id="firstname"
type="text" size="25" maxlength="30"
onkeyup="upperCase(this)" ></td>
</tr>
<tr>
<td align="right"><span id="3">Last Name </span>
</td>
<td><input name="lastname" onkeyup="upperCase(this)" id="lastname" type="text"
size="25"
></td>
</tr>
<tr>
<td align="right"><span id="4">Address 1 </span>
</td>
<td><input name="address1" onkeyup="upperCase(this)" id="address1" type="text"
size="25"
></td>
</tr>
<tr>
<td align="right"><span id="5">Address 2 </span>
</td>
<td><input name="address2" onkeyup="upperCase(this)" id="address2" type="text"
size="25"
></td>
</tr>
<tr>
<td align="right"><span id="6">City </span>
</td>
<td><input name="city"  onkeyup="upperCase(this)" id="city" type="text"
size="25"
></td>
</tr>
<tr>
<td align="right"><span id="7">State </span>
</td>
<td><input  name="state" id="state" type="text"
size="25"></td>
</tr>
<tr>
<td align="right"><span id="8">Zip Code </span>
</td>
<td><input name="zipcode" id="zipcode" type="text"
size="25" maxlength="8"
></td>
</tr>
<tr>
<td align="right"><span id="9">Phone Number </span>
</td>
<td><input name="phone" id="phone" type="text"
size="25" maxlength="14"
></td>
</tr>
<tr>
<td align="right"><span id="10">Fax Number </span>
</td>
<td><input name="fax" id="fax" type="text" size="25"
maxlength="14"
></td>
</tr>
</table>
<input type="button" value="Submit" onClick="validate();">
</form>
</div>

<br />
<!-- google_ad_section_start(weight=ignore) -->
<FONT Size="1"> </FONT>
</td>
<div align="center">
</noscript>
<!-- End Quantcast tag -->
<br />
<br />
</div>
</td>
</tr>
</table>
</font>
</div>
</font>
</body>
</html>

JavaScript Time Clock Show Technique

<html>
<head>
</head>
<body>
<form name="Tick">
<input type="text" size="11" name="Clock">
</form>
<script>

function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="AM"

if (hours>12){
dn="PM"
hours=hours-12
}

if (hours==0)
hours=12

if (minutes<=9)
minutes="0"+minutes

if (seconds<=9)
seconds="0"+seconds
document.Tick.Clock.value=hours+":"+minutes+":"
+seconds+" "+dn
setTimeout("show()",1000)
}

show()

</script>
</body>
</html>

Marque Example in JavaScript


<html>
<head>
<!--
<script>
    function startLoop() {
    setInterval( "doSomething()", 5000 ); }
    function doSomething() {
    document.getElementById('myMarquee').stop(); }
</script>
-->
<script>
var step = 1; // marquee is run on load time
function startLoop()
{
    setInterval("doSomething()", 4000 );
}
function doSomething()
{
    if (step == 0) {
        // 5 seconds are passed since marquee stopped
        document.getElementById('myMarquee').start();
        step = 1;
    }
    else
    {
        if (step == 1) {
            // 5 seconds are passed since marquee started
            step = 2; // Just delay of another 5 seconds before stop
        }
        else
        {
            if (step == 2) {
                // 10  seconds are passed since marquee started
                document.getElementById('myMarquee').stop();
                step = 0;
            }
        }
    }              
}
</script>


</head>
<body onload="startLoop();">
<table width=30% border=2>
  <tr>
    <td width=100% align=center
      valign=center>
      <marquee align="middle"
         behavior="scroll" 
 id="myMarquee"
        bgcolor="Black"
        direction="up"
align="center"
        height="200"
        width="100%"
onmouseover="this.stop();"
onmouseout="this.start();"
        scrollamount="1"
        scrolldelay="50">
        <font color="#30ec0f" 
        size=2><b>
        Text 1
        </b></font>
<font color="#de082d" 
        size=2><b><br><br><br>
Text2
</b></font>
<b><br><br><br>
 <font color="#30ec0f" 
        size=2><b>
       Text 3
        </b></font>
<font color="#de082d" 
        size=2><b><br><br><br>
      </marquee>
    </td>
  </tr>
</table>

</body>
</html>

Java Collections Examples

Java Collection Interface

Java - The Set Interface 



Example of Collection -- ArrayList

package org.collection;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;

public class Class1 {
   public Class1() {
    }
    public static void main(String[] args) {
    List l = new ArrayList();
    l.add(new Integer(20));
    l.add(new Float(69.40));
    l.add(new Integer(56));
    l.add(new Double(49399.9929300));

    List<String> l1 = new ArrayList<String>();
    l1.add("Aman Kumar");
    l1.add("Nitin Rajput");
    l1.add("Mukesh Kumar");
    l1.add("Nidhi Goyal");
    l1.add("Brijesh Bhagat");
    l1.add("Kapil vardhan");
    l1.add("Kapil Gupta");
    l1.add("Chetan Shishodia");
    l1.add("Kapil Kumar");
    System.out.println("Before Sort :"+l1);
    Collections.sort(l1);
    System.out.println("After Sort :"+l1);
    }

}

 
// ------------ Search Elements in Array List -------------- //

package arraylist;

import java.util.ArrayList;

public class SearchAnElementInArrayListExample {
  
    public static void main(String args[]){
      
        ArrayList arraylist= new ArrayList();
        arraylist.add("5");
        arraylist.add("10");
        arraylist.add("1");
        arraylist.add("4");
        arraylist.add("8");
        arraylist.add("3");
        arraylist.add("9");
        arraylist.add("2");
      
        boolean found = arraylist.contains("40");
        System.out.println("Does ArrayList contains 4 "+found);
      
        int index = arraylist.indexOf("80");
        if(index == -1)
        System.out.println("element 80 not found...");
        else
        System.out.println("element 80 found...");  
      
        int lastindex = arraylist.lastIndexOf("9");
        if(lastindex== -1)
        System.out.println("element 9 not exist...");
        else
        System.out.println("element 9 is exist");  
    }

}



Jquery Slide Toggle Events

<!--  Jquery Slide Toggle  Events -->

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
       
        <script type="text/javascript" src="jquery-1.4.1.js"></script>
        <script type ="text/javascript">
            $(document).ready(function() {
                $("#btnsubmit").click( function() {
                    $("#slide").slideToggle('slow');
                    return false;
                });
            });
           
        </script>     

    </head>
    <body>
        <h1>Hello World!</h1>
        <a>Name: </a><input type="text" id="txtid" size="15"/>
        <form method="post" action="index.jsp">
           
        <input type="submit" id ="btnsubmit" />
        <div id ="slide" style ="height:200px; width: 200px; background-color: green; "> </div>
        </form>
   </body>
</html>