Showing posts with label JAvascript. Show all posts
Showing posts with label JAvascript. Show all posts

Wednesday, October 4, 2017

Store data in mysql for all the languages to use character set

 Store data in mysql for all the languages to use character set


HTML HEAD TAG



MYSQL DATABASE CONNECTION

mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');

Saturday, February 16, 2013

Email Validation With RegExp In Jquery and Javascript

Email Validation With RegExp In Jquery and Javascript

$(document).ready(function() {

   $('#btnSubmit').click(function() {
 
var sEmail = $('#txtEmail').val();
if ($.trim(sEmail).length == 0) {
alert('Please enter valid email address');
e.preventDefault();
}

// example 1
if (validateEmail(sEmail)) {
alert('Invalid Email Address');
e.preventDefault();

} else {
alert('Email is valid');
}
// example 2
if (validate_email(sEmail)) {
alert('Invalid Email Address');
e.preventDefault();

} else {
alert('Email is valid');
}

// example 3
if (IsEmail(sEmail)) {
alert('Invalid Email Address');
e.preventDefault();

} else {
alert('Email is valid');
}
});
});

function validateEmail(sEmail)
{
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!filter.test(sEmail)) {
return false;
} else {
return true;
}
}
function validate_email(email)
{
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(email)) {
return false;
} else {
return true;
}
}

function IsEmail(email)
{
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!regex.test(email)) {
return false;
} else {
return true;
}
}


Thursday, July 14, 2011

Div Scrollable Contents on MouseOver On Javascript




SCROLLABLE DIV CONTENTS WHEN MOUSE OVER THE SCROLL UP AND SCROLL DOWN LINKS
SCROLLABLE DIV CONTENTS WHEN MOUSE OVER THE UP AND DOWN LINKS The top-level function, escape, encodes the string that is contained in the string argument to make it portable. A string is considered portable if it can be transmitted across any network to any computer that supports ASCII characters. We can use escape function in JavaScript to make a string portable to transmit it over a network. All the non ASCII characters are to be converted before sending them by using escape function. The escape function will replace these non ASCII characters to its two or four digit hex format.
Scroll Up Scroll Down

Here Code


<html>
<script type="text/javascript">
var scrolling = null;
var _speed = 12;


function doScrollUp()
{
var d = document.getElementById('scroller');
d.scrollTop = d.scrollTop - _speed;


scrolling = window.setTimeout(function() {
doScrollUp();
}, 100);
}


function doScrollDown()
{
var d = document.getElementById('scroller');
d.scrollTop = d.scrollTop + _speed;


scrolling = window.setTimeout(function() {
doScrollDown();
}, 100);
}


function doStopScroll()
{
window.clearTimeout(scrolling);
}
</script>
<body>
<h2>SCROLLABLE DIV CONTENTS WHEN MOUSE OVER THE UP AND DOWN LINKS</h2>
<div id="scroller" style="width:100%; height:100px; overflow:hidden;">


SCROLLABLE DIV CONTENTS WHEN MOUSE OVER THE UP AND DOWN LINKS
<br /><br /><br />
The top-level function, escape, encodes the string that is contained in <br /><br />
the string argument to make it portable. A string is considered portable <br /><br />
if it can be transmitted across any network to any computer that
supports ASCII characters.<br />
We can use escape function in JavaScript to make a string portable
to transmit it over a network. All the non ASCII characters are to be <br />
converted before sending them by using escape function. The escape function <br />
will replace these non ASCII characters to its two or four digit hex format.<br />
<br /><br /><br /><br />
</div>
<div>
<span style="color:red;" onmouseover="doScrollUp();" onmouseout="doStopScroll();" style="padding-right:10px;">Scroll Up</span>
<span style="color:blue;" onmouseover="doScrollDown();" onmouseout="doStopScroll();">Scroll Down</span>
</div>


</body>
</html>

Tuesday, July 12, 2011

Escape Function in Javascript or Jquery

Escape Function:


The escape() function encodes a string.


<script type="text/javascript">
unescape("you can pass & symbols & any other special characters through query string when you using ajax posting & jquery posting");
</script>
The top-level function, escape, encodes the string that is contained in the string argument to make it portable. A string is considered portable if it can be transmitted across any network to any computer that supports ASCII characters.
We can use escape function in JavaScript to make a string portable to transmit it over a network. All the non ASCII characters are to be converted before sending them by using escape function. The escape function will replace these non ASCII characters to its two or four digit hex format.
 The escape function converts a blank space into %20, same way it converts & to %26.



The unescape() function decodes an encoded string.


<script type="text/javascript">
unescape("you%20can%20pass%20&%20symbols &%20any%20other%20special characters%20through%20query%20string when%20you%20using%20ajax%20posting &%20jquery%20posting");
</script>

Saturday, January 15, 2011

Login Screen Shaking

Shaking the Login Screen.  when u can refresh the page and submit the page....

 <!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>
<script type="text/javascript">
          addLoadEvent = function(func){
            if (typeof jQuery!="undefined")
                jQuery(document).ready(func);
           
            else if ( typeof wpOnload!='function'){
                wpOnload=func;
            } else {
                var oldonload=wpOnload;
                wpOnload=function(){
                    oldonload();
                    func();
                }
            }
        };
       
        function s(id,pos){
            g(id).left = pos+'px';
        }
        function g(id){
            return document.getElementById(id).style;
        }
        function shake(id,a,d) {
            c=a.shift();
            s(id,c);
            if(a.length>0){
                setTimeout(function(){
                    shake(id,a,d);
                },d);
            } else {
                try {
                    g(id).position='static';
                    wp_attempt_focus();
                }
                catch(e){}
            }
        }
       
        addLoadEvent(function(){
            var p = new Array(10, 10, 10, 0, -10, -10, -10, 0);
            p = p.concat(p.concat(p));
            var i = document.forms[0].id;g(i).position='relative';
            shake(i, p, 20);
        });
  </script>


</head>
<body onload="document.getElementById('username').focus();">
<table width="90%" cellpadding="0" cellspacing="0" border="0" align="center">
   <tr>
      <td valign="top">
         <form method="post" action="" name="frmLogin" id="frmLogin">
                 <table width="50%" cellpadding="2" cellspacing="2" border="1" align="center">
                         <tr><td height="10px"></td></tr>
                          <tr>
                        <td width="40%"> USERNAME:</td>
                         <td width="60%">
                                 <input type="text" name="username" id="username" autocomplete="off" />
                      </td>
                      </tr>
                       <tr>
                       <td>PASSWORD: </td>
                      <td>
                       <input type="password" name="password" id="password" autocomplete="off" />
                   </td>
               </tr>             </table>
      </form>
  </td>
</tr>
</table>
</body>
</html>
<script type="text/javascript">
    function wp_attempt_focus(){
        setTimeout( function() {
            try {
                d = document.getElementById('username');
                d.value = '';
                d.focus();
            } catch(e){}
        }, 200);
    }
     wp_attempt_focus();
    if(typeof wpOnload == 'function')wpOnload();
  </script>

Thursday, May 21, 2009

Creating an XMLHttp Object in PHP AJAX

The first step to using an XMLHttp object is, obviously, to create one. Because Microsoft's implementation is an ActiveX control, you must use the proprietary ActiveXObject class in JavaScript, passing in the XMLHttp control's signature:
var oXmlHttp = new ActiveXObject("Microsoft.XMLHttp");
This line creates the first version of the XMLHttp object (the one shipped with IE 5.0). The problem is that there have been several new versions released with each subsequent release of the MSXML library. Each release brings with it better stability and speed, so you want to make sure you are always using the most recent version available on the user's machine. The signatures are:
1 Microsoft.XMLHttp 2 MSXML2.XMLHttp 3 MSXML2.XMLHttp.3.0 4 MSXML2.XMLHttp.4.0 5 MSXML2.XMLHttp.5.0
Unfortunately, the only way to determine the best version to use is to try to create each one. Because this is an ActiveX control, any failure to create an object will throw an error, which means that you must enclose each attempt within a try...catch block. The end result is a function such as this:
function createXMLHttp() { var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ]; for (var i = 0; i < oxmlhttp =" new">
The createXMLHttp() function stores an array of XMLHttp signatures, with the most recent one first. It iterates through this array and tries to create an XMLHttp object with each signature. If the creation fails, the catch statement prevents a JavaScript error from stopping execution; then the next signature is attempted. When an object is created, it is returned. If the function completes without creating an XMLHttp object, an error is thrown indicating that the creation failed. Fortunately, creating an XMLHttp object is much easier in other browsers. Mozilla Firefox, Safari, and Opera all use the same code:
var oXmlHttp = new XMLHttpRequest();
Naturally, it helps to have a cross-browser way of creating XMLHttp objects. You can create such a function by altering the createXMLHttp() function defined previously: function createXMLHttp() { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ]; for (var i = 0; i < oxmlhttp =" new">
The other option for creating cross-browser XMLHttp objects is to use a library that already has cross-browser code written. The zXml library, written by two of your authors, is one such library and is available for download at www.nczonline.net/downloads/. This library defines a single function for the creation of XMLHttp objects: var oXmlHttp = zXmlHttp.createRequest(); The createRequest() function, and the zXml library itself, will be used throughout this book to aid in cross-browser handling of Ajax technologies. Using XMLHttp After you have created an XMLHttp object, you are ready to start making HTTP requests from JavaScript. The first step is to call the open() method, which initializes the object. This method accepts the following three arguments:
Request Type: A string indicating the request type to be made — typically, GET or POST (these are the only ones currently supported by all browsers). URL: A string indicating the URL to send the request to. Async: A Boolean value indicating whether the request should be made asynchronously.
The last argument, async, is very important because it controls how JavaScript executes the request. When set to true, the request is sent asynchronously, and JavaScript code execution continues without waiting for the response; you must use an event handler to watch for the response to the request. If async is set to false, the request is sent synchronously, and JavaScript waits for a response from the server before continuing code execution. That means if the response takes a long time, the user cannot interact with the browser until the response has completed. For this reason, best practices around the development of Ajax applications favor the use of asynchronous requests for routine data retrieval, with synchronous requests reserved for short messages sent to and from the server. To make an asynchronous GET request to info.txt, you would start by doing this:
var oXmlHttp = zXmlHttp.createRequest(); oXmlHttp.open("get", "info.txt", true);
Note that the case of the first argument, the request type, is irrelevant even though technically request types are defined as all uppercase. Next, you need to define an onreadystatechange event handler. The XMLHttp object has a property called readyState that changes as the request goes through and the response is received. There are five possible values for readyState:
0 (Uninitialized): The object has been created but the open() method hasn't been called. 1 (Loading): The open() method has been called but the request hasn't been sent. 2 (Loaded): The request has been sent. 3 (Interactive). A partial response has been received. 4 (Complete): All data has been received and the connection has been closed.
Every time the readyState property changes from one value to another, the readystatechange event fires and the onreadystatechange event handler is called. Because of differences in browser implementations, the only reliable readyState values for cross-browser development are 0, 1, and 4. In most cases, however, you will check only for 4 to see when the request has returned: var oXmlHttp = zXmlHttp.createRequest(); oXmlHttp.open("get", "info.txt", true); oXmlHttp.onreadystatechange = function () { if (oXmlHttp.readyState == 4) { alert("Got response."); } }; The last step is to call the send() method, which actually sends the request. This method accepts a single argument, which is a string for the request body. If the request doesn't require a body (remember, a GET request doesn't), you must pass in null:
var oXmlHttp = zXmlHttp.createRequest(); oXmlHttp.open("get", "info.txt", true); oXmlHttp.onreadystatechange = function () { if (oXmlHttp.readyState == 4) { alert("Got response."); } }; oXmlHttp.send(null); That's it! The request has been sent and when the response is received, an alert will be displayed. But just showing a message that the request has been received isn't very useful. The true power of XMLHttp is that you have access to the returned data, the response status, and the response headers.
To retrieve the data returned from the request, you can use the responseText or responseXML properties. The responseText property returns a string containing the response body, whereas the responseXML property is an XML document object used only if the data returned has a content type of text/xml. (XML documents are discussed in Chapter 4.) So, to get the text contained in info.txt, the call would be as follows:
var sData = oXmlHttp.responseText;
Note that this will return the text in info.txt only if the file was found and no errors occurred. If, for example, info.txt didn't exist, then the responseText would contain the server's 404 message. Fortunately, there is a way to determine if any errors occurred. The status property contains the HTTP status code sent in the response, and statusText contains the text description of the status (such as "OK" or "Not Found"). Using these two properties, you can make sure the data you've received is actually the data you want or tell the user why the data wasn't retrieved: if (oXmlHttp.status == 200) { alert("Data returned is: "+ oXmlHttp.responseText; } else { alert("An error occurred: "+ oXmlHttp.statusText; } Generally, you should always ensure that the status of a response is 200, indicating that the request was completely successful. The readyState property is set to 4 even if a server error occurred, so just checking that is not enough. In this example, the responseText property is shown only if the status is 200; otherwise, the error message is displayed. Important The statusText property isn't implemented in Opera and sometimes returns an inaccurate description in other browsers. You should never rely on statusText alone to determine if an error occurred. As mentioned previously, it's also possible to access the response headers. You can retrieve a specific header value using the getResponseHeader() method and passing in the name of the header that you want to retrieve. One of the most useful response headers is Content-Type, which tells you the type of data being sent:
var sContentType = oXmlHttp.getResponseHeader("Content-Type"); if (sContentType == "text/xml") { alert("XML content received."); } else if (sContentType == "text/plain") { alert("Plain text content received."); } else { alert("Unexpected content received."); } This code snippet checks the content type of the response and displays an alert indicating the type of data returned. Typically, you will receive only XML data (content type of text/xml) or plain text (content type of text/plain) from the server, because these content types are the easiest to work with using JavaScript. If you'd prefer to see all headers returned from the server, you can use the getAllResponseHeaders() method, which simply returns a string containing all of the headers. Each heading in the string is separated by either a new line character (\n in JavaScript) or a combination of the carriage return and new line (\r\n in JavaScript), so you can deal with individual headers as follows:
var sHeaders = oXmlHttp.getAllResponseHeaders(); var aHeaders = sHeaders.split(/\r?\n/); for (var i=0; i <>
It's also possible to set headers on the request before it's sent out. You may want to indicate the content type of data that you'll be sending, or you may just want to send along some extra data that the server may need to deal with the request. To do so, use the setRequestHeader() method before calling send():
var oXmlHttp = zXmlHttp.createRequest(); oXmlHttp.open("get", "info.txt", true); oXmlHttp.onreadystatechange = function () { if (oXmlHttp.readyState == 4) { alert("Got response."); } }; oXmlHttp.setRequestHeader("myheader", "myvalue"); oXmlHttp.send(null); In this code, a header named myheader is added to the request before it's sent out. The header will be added to the default headers as myheader: myvalue. Up to this point, you've been dealing with asynchronous requests, which are preferable in most situations. Sending synchronous requests means that you don't need to assign theonreadystatechange event handler because the response will have been received by the time the send() method returns. This makes it possible to do something like this: var oXmlHttp = zXmlHttp.createRequest(); oXmlHttp.open("get", "info.txt", false); oXmlHttp.send(null); if (oXmlHttp.status == 200) { alert("Data returned is: "+ oXmlHttp.responseText; } else { alert("An error occurred: "+ oXmlHttp.statusText; }
Sending the request synchronously (setting the third argument of open() to false) enables you to start evaluating the response immediately after the call to send(). This can be useful if you want the user interaction to wait for a response or if you're expecting to receive only a very small amount of data (for example, less than 1K). In the case of average or larger amounts of data, it's best to use an asynchronous call.

Friday, January 23, 2009

Local Search Control Programming Guide in Google API - Local Search Control for Google Maps

Instructions for adding this to your site
Assuming you already have a working maps application, adding the control is a simple two step process (alternatively,you can always start with "hello world" starter andthen customize the esulting code.)
Step 1 - Load AJAX Search API and Local Search Control for Google Maps

// Load the Code
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAipgi6ppj9z1Np5lR2SFXbBSMWlLVwX1ylsLSaLe34pMM37gB9hQjNUQFvLuLRgiSMzRlZIgxSIE1vw"
type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js"
type="text/javascript"></script>

// Load the Style Sheets
<style type="text/css">
@import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
</style>

The first step is to load the Google AJAX Search API and the Local Search Control code and style sheet into your application. The AJAX Search API uses the same key system that Google Maps API uses, so just use your maps key where required.

// Load the Code
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAipgi6ppj9z1Np5lR2SFXbBSMWlLVwX1ylsLSaLe34pMM37gB9hQjNUQFvLuLRgiSMzRlZIgxSIE1vw"
type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js"
type="text/javascript"></script>

// Load the Style Sheets
<style type="text/css">
@import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
</style>

Step 2 - Create a Local Search Control
The next step is to create a Local Search control and add it to your map.

// create your map
var map = new GMap2(document.getElementById("map"));
// create a local search control and add it to your map
map.addControl(new google.maps.LocalSearch());

Customizing the Local Search Control and Other Advanced Features
The Local Search Control for Google Maps contains a number of options that you control.

* Result List Format and Placement Control
* Setting the Link Target
* Custom Search Form Hint Text
* Idle and Search Completion Callbacks
* Marker Html Generation and Markers Set CallbacksNew!
* Setting Focus on the Search Control
* First Result Info Window Suppression
* Suppress Default Zoom on Search Complete

Result List Format and Placement Control

By default, when a search completes, the search results are placed on your map and they are also listed in tabular form above the search form input. By using the opt_options argument to the control, you can specify this default behavior, you can suppress the tabular display of
the search results, or you can provide us with a container element and we will place the tabular results within your container. The following snippets and samples demonstrate these options.
Suppressed Tabular Result List
The following snippet and sample demonstrates how to suppress the tabular result list.

<script type="text/javascript">
// request that tabular search results should be suppressed
var options = {
resultList : google.maps.LocalSearch.RESULT_LIST_SUPPRESS
};
map.addControl(new google.maps.LocalSearch(options));
</script>

Default Tabular Result List
The following snippet and sample demonstrates how to request the default tabular result list.

<script type="text/javascript">
// no option needed, this is the default
map.addControl(new google.maps.LocalSearch());

// BUT, If you want to, you can explicityly request the default
var options = {
resultList : google.maps.LocalSearch.RESULT_LIST_INLINE
};
map.addControl(new google.maps.LocalSearch(options));
</script>

External Tabular Result List
The following snippet and sample demonstrates how to request that the tabular result list be displayed in a container of your choice.
<script type="text/javascript">

// request that tabular search results be displayed in an external container
var options = {
resultList : document.getElementById("results")
};
map.addControl(new google.maps.LocalSearch(options));
...
<div id="results">Loading...</div>
</script>

Setting the Link Target

This option allows you to set the link target used for links embedded in the Local Search Control. The default value is GSearch.LINK_TARGET_BLANK which specifies that will open in a new window. To change this behavior, simply use the linkTarget property of options and supply a value of GSearch.LINK_TARGET_SELF to open links in the current new window, Search.LINK_TARGET_BLANK to open links in a new window, GSearch.LINK_TARGET_TOP to open links in the topmost frame,
GSearch.LINK_TARGET_PARENT to open links in the parent frame or to replace the current frame.
You can also specify any other value which will be used as the value of the target property on all links.

/*** open links in the current window*/

var options = {
linkTarget : GSearch.LINK_TARGET_SELF
};
map.addControl(new google.maps.LocalSearch(options));

Custom Search Form Hint Text

When the search control is in its idle state, the search form normally contains localized
search hint text, e.g.: "search the map". Using this option, you can supply your own custom hint
text.

var options = {
searchFormHint : "Example Searches: Hotels in New York City"
};
map.addControl(new google.maps.LocalSearch(options));

Idle and Search Completion Callbacks

In some cases, its useful for an application to know when a search has completed and when the earch control goes idle. For instance, when the search control goes idle, the application may want to recenter the map. When a search completes, an application may want to alter the zoom level of the map. These are easily accomplished by using the search control callbacks.
Search Control Idle Callback
The search control idle callback is called when the search control finishes its initial load and whenever search results are dismissed. The following snippet demonstrates how to use this.

// request an "on idle" callback. This is called when a search is dismissed and
// when the search control initially loads
var options = {
onIdleCallback : function() { alert("search control is idle");}
};
map.addControl(new google.maps.LocalSearch(options));

Search Complete Callback
The search complete callback is called whenever a search completes. It is passed the localSearch object associated with the search control. It is called before results are placed on the map or into the tabular results list. The following snippet demonstrates how to use this.

// request an "on search complete" callback. This is called when a search completes
// and before results are placed on the map or tabular tabular result list
var options = {
onSearchCompleteCallback : function(searcher){
alert(searcher.results.length + " results");
}
};
map.addControl(new google.maps.LocalSearch(options));

Marker Html Generation and Markers Set CallbacksNew!

The callbacks listed above give your application basic notifications that a search has completed
and that the user is done using the control. The marker oriented callbacks described in this section are designed to allow you to participate in the html generation phase of a search result's
info window as well as providing you with direct access to the markers once they have been placed on the map.
Generate Marker HTML Callback
When the info window for a marker representing a search result is opened, this callback is executed in order to allow you to participate in the html generation. For instance, suppose you want to add a link to the info window, or add a photo, or whatever makes sense for your application. The following snippet shows how to do this.

// request an "on generate marker html" callback. This is called during the open of an info window.
var options = {
onGenerateMarkerHtmlCallback : extendMarker
};
map.addControl(new google.maps.LocalSearch(options));
...
function extendMarker(marker, html, result) {
// extend the passed in html for this result
myStuff = document.createElement("div");
div.innerHTML = "Bookmark This Result...";
html.appendChild(div);
return html;
}

Markers Set Callback
The Search Complete callback calls your application before the search results are converted into markers and placed on the map. This allows your application to inspect and process the raw results. The onMarkersSetCallback calls your application after the search complete callback, and after the results are processed and placed on the map. This callback allows you to inspect and
process the markers, etc. The sample below demonstrates this callback. Normally, after a search completes, the first marker's info window is opened. Using this callback, you can open an alternate info window (maybe the info window of one of your partners, etc.)
// request an "on markers set" callback.

var options = {
onMarkersSetCallback : markersSet
};
myLocalSearchControl = new google.maps.LocalSearch(options);
map.addControl(myLocalSearchControl);
...
function markersSet(markers) {
// note: markers is an array of LocalResult
if (markers.length > 1) {
// grab the title of the 2nd result object
// if it matches starbucks, then alert
var title = markers[1].result.titleNoFormatting;
if (title.search(/starbucks/i) >= 0) {
alert(markers[1].result.titleNoFormatting);
}
}
}

Setting Focus on the Search Control
Applications may use the focus() method on the search control to force focus to the search form's input box.

var searchControl = new google.maps.LocalSearch();
map.addControl(searchControl);
...
searchControl.focus();

First Result Info Window Suppression
Normally, when a search completes, the first search result is selected, the map is panned to this
result, and the info window associated with the result is opened. This option allows an application to suppress this initial info window open.

// request the the initial search result info window should not be
// auto-opened
var options = {
suppressInitialResultSelection : true
};
map.addControl(new google.maps.LocalSearch(options));

Suppress Default Zoom on Search CompleteNew!
Normally, when a search completes, the map is re-positioned and zoomed in so that it shows all of the results. Applications can disable this move/zoom operation by setting the suppressZoomToBounds option to false. The HotLinks sample demonstrates this. The other interesting thing this sample does is demonstrate how to use the search control's .execute() method to do initiate a search from your own code. Note the Featured Locations links beneath the map.

// instruct the system to NOT zoom on search complete
var options = {
suppressZoomToBounds : true
};
map.addControl(new google.maps.LocalSearch(options));

The "Hello World" of the Local Search Control for Google Maps

The following page demonstrates a complete page which uses the Local Search Control
for Google Maps. You can start with this simple page, change YOUR-KEY to the value of
your key and be up and running in seconds.

Warning: Make sure you signup for your own key. Do not use the key value of "YOUR-KEY" on your pages.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
<title>Local Search Control for Google Maps -
default.html</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=
ABQIAAAAipgi6ppj9z1Np5lR2SFXbBSMWlLVwX1ylsLSaLe34pMM37gB9hQjNUQFvLuLRgiSMzRlZIgxSIE1vw" type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&
v=1.0&key=YOUR-KEY" type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js"
type="text/javascript"></script>
<style type="text/css">
@import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch
/gmlocalsearch.css");
#map {
border : 1px solid #979797;
width : 100%;
height : 600px;
}
</style>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
// Create and Center a Map
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(12.4419, 79.1419), 13);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
// bind a search control to the map, suppress result list
map.addControl(new google.maps.LocalSearch());
}
}
GSearch.setOnLoadCallback(load);
//]]>
</script>
</head>
<body onunload="GUnload()">
<div id="map"></div>
</body>
</html>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
<title>Local Search Control for Google Maps -
default.html</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=
ABQIAAAAipgi6ppj9z1Np5lR2SFXbBSMWlLVwX1ylsLSaLe34pMM37gB9hQjNUQFvLuLRgiSMzRlZIgxSIE1vw"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
google.load("search", "1");
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();
// Add in a full set of searchers
var localSearch = new google.search.LocalSearch();
searchControl.addSearcher(localSearch);
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.VideoSearch());
searchControl.addSearcher(new google.search.BlogSearch());
// Set the Local Search center point
localSearch.setCenterPoint("India, India");
// Tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"));
// Execute an inital search
searchControl.execute("Google");
}
google.setOnLoadCallback(OnLoad);>
</script>
</head>
<body onunload="GUnload()">
<div id="searchcontrol">Loading...</div>
</body>
</html>