Showing posts with label JAVA Script. Show all posts
Showing posts with label JAVA Script. Show all posts

Sunday, 21 April 2013

AutoComplet TextBox (MultiValue)

Step 1:
create JSP Page and add Control on Page












Step 2:
Create a array list and add mail id on array list

for eg

 public static  ArrayList<String> usermail()
                 {
                ArrayList<String> list11=null;
                try {
                   list11 = new ArrayList<String>();
                if(con.isClosed())
{
openConnection();
}
                   String Query="SELECT Email FROM personal_info";
                   statement=con.createStatement();
                   ResultSet rs=statement.executeQuery(Query);
                   System.out.println(Query);
                 while(rs.next())
                 {
                            list11.add(rs.getString("Email"));
                             }
                }catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
                                
             return list11;
                 }


Step 3:
Access array list On JSP Page
import class on JSP page

<%@ page import="java.util.*,util.*,dao.*;" %>
<%
  ArrayList<String> usermail= VisitorOutPassDAO.usermail();
%>

Step 4:
Given code on Java script


<script type="text/javascript">
$(function() {
var availableTags= new Object([]);
<%! int i=0;%>
<%
for(i=0;i<usermail.size();i++)
{
%>
availableTags[<%= i %>]='"<%= usermail.get(i) %>"';
<%}%>
//availableTags = availableTags.substring(0, availableTags.length - 1);
//availableTags+="]";
alert(availableTags);
    function split( val ) {
     return val.split( /,\s*/ );
   
  }
  function extractLast( term ) {
    return split( term ).pop();
  }

  $( "#mailId" )
//don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "ui-autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
//delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
//prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );

//remove the current input
terms.pop();
//add the selected item
terms.push( ui.item.value );

var selected_cust_name=ui.item.value;
var all_selected_cust=$("#mailId").val();
var index=all_selected_cust.indexOf(selected_cust_name);
//add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( "," );
if(index!=-1)
{
all_selected_cust=$("#mailId").val();
var all_len=all_selected_cust.length;
var seleced_len=selected_cust_name.length;
seleced_len++;
var last_index=all_len-seleced_len;
if(last_index!=0)
{
var final_value=all_selected_cust.substring(0,last_index);
$("#mailId").val(final_value);
}
alert("Already selected.");
}
return false;
}
});
});
}
</script>

Out Put








Friday, 29 March 2013

Print and Print Preview separately using HTML, CSS and JavaScript


Code:

<html>
<body  id="printarea">
    <table class="tble">
        <tr>
            <td>
                Student Name
            </td>
            <td>
                John Sypon
            </td>
        </tr>
        <tr>
            <td>
                Student Rollnumber
            </td>
            <td>
                R001
            </td>
        </tr>
        <tr>
            <td>
                Student Address
            </td>
            <td>
                132 Kane Street Toledo OH 43612.
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="Print" class="btn" onclick="PrintDoc()"/>
            </td>
            <td>
                <input type="button" value="Print Preview" class="btn" onclick="PrintPreview()"/>
            </td>
        </tr>
    </table>
</body>
</html>

We can add the css file in our html file:
<link rel="stylesheet" type="text/css" href="print.css" />
<link rel="stylesheet" type="text/css" href="Style.css" />

Output:

Print and Print Preview separately using HTML, CSS and JavaScript
And I am also added two CSS for make fine-looking our application, below is listed both css:
1.       Print.css
2.       Style.css

Print.css:

The Print.css file is making a fine-looking our application when we give the print or print preview command. Below is Print.css file code.
@media print /*--This is for Print--*/
{
    .btn
    {
        display: none;
    }
    .tble
    {
        background-color: #CD853F;
        border:1px solid green;
        -webkit-print-color-adjust: exact

/*above line of codes will set the table background-color and change the border color when we give the print and preview (print preview only when we see on print preview via browser) command*/
    }
   
}
@media screen /*--This is for Print Preview Screen--*/
{
    .btn
    {
        display: none;
    }
    .tble
    {
        background-color: #CD853F;
        border:1px solid green;
    }
}

Above @media screen use for change the style when we show on print preview, this print preview is made by itself in our application, I am creating this print preview using javascript in a window format and we also known as every html application is need the style for stunning our application, and@media screen is provide the style when we open that application in new window as print preview.

Style.css

@media screen /*--This is for Screen--*/
{
    .btn
    {
        background-color: #AFAFAF;
        display: block;
    }
    .tble
    {
        background-color: #E5E5E5;
        border: 1px solid #CD853F;
    }
}

Above Stylesheet code will provide the style of our application on screen (means on browser).

JavaScript:

Here I am using the javascript which is made a window where we give the print command.
<script type="text/javascript">
/*--This JavaScript method for Print command--*/
    function PrintDoc() {
        var toPrint = document.getElementById('printarea');
        var popupWin = window.open('', '_blank', 'width=350,height=150,location=no,left=200px');
        popupWin.document.open();
        popupWin.document.write('<html><title>::Preview::</title><link rel="stylesheet" type="text/css" href="print.css" /></head><body onload="window.print()">')
        popupWin.document.write(toPrint.innerHTML);
        popupWin.document.write('</html>');
        popupWin.document.close();
    }
/*--This JavaScript method for Print Preview command--*/
    function PrintPreview() {
        var toPrint = document.getElementById('printarea');
        var popupWin = window.open('', '_blank', 'width=350,height=150,location=no,left=200px');
        popupWin.document.open();
        popupWin.document.write('<html><title>::Print Preview::</title><link rel="stylesheet" type="text/css" href="Print.css" media="screen"/></head><body">')
        popupWin.document.write(toPrint.innerHTML);
        popupWin.document.write('</html>');
        popupWin.document.close();
    }
</script>