Input validating of search text

This Javascript validates the users input to the search-text, before submitting it to Google.

The pre-defined text (Google search) will disappear when the user clicks on the input box (onfocus). The text will be shown again, when the user clicks elsewhere (onblur).

 

Here is the javascript to be included between <head> and </head>:

<script type="text/javascript">

function Validering()
{
error = 0;

if((document.sform.q.value=='Google search' ) && (error==0))
{
alert('Please write a text for your search :-)');
document.sform.q.focus();
error = 1;
}

if(error == 0)
{
document.sform.submit();
}
}
</script>

Include this html code in the desired position on the webpage, where you want the search-form to be shown:

<form name="sform" method="get" action="http://www.google.com/search" target="_blank" onsubmit="Validering(); return false;">

<input type="text" name="q" size="20" value="Google search" onblur="if (value == '') {value = 'Google search'}" onfocus="if (value == 'Google search') {value =''}"/>

<input type="submit" name="send" value="Search"/>

</form>

 

Could You use this script? Please donate a little amount...



...to the development of more scripts :-)
Validering af tekst til søgning

Input validating of search text

Denne side på dansk Validering af tekst til søgning  
 
Front page Read/sign my guestbook Sitemap Send mail  Bookmark and Share
Valid XHTML 1.0!