loading...

Posts Tagged ‘javascript’

Clearing contents of a input box when a user clicks in it

a post by Alec, filed in Computer, Websites, how to, html, internet, media, technology on January 18th, 2008. Read the full post »

One of the most annoying things I find in a website is a search bar that says “Search Here…” or something of those likes, because when you click in that box you have to manually erase the text, it is not a big thing but it is very easy to solve. All you need to do is copy and paste this code into the <input /> tag.

Code Snippet:
onfocus="this.value=''"

Full Code:
<input type="text" name="test" value="search" onfocus="this.value=''" />

Example:

Now this won’t work if the user has Javascript turned off, but that is their fault not yours. This only works on <input type=”text” />

Look for my article on the basics of CSS soon.

Javascript Redirect

a post by Alec, filed in Websites, html, internet on January 17th, 2008. Read the full post »

This is a Javascript Redirect with a delay of 3 seconds


<script type="text/javascript">
<!--
setTimeout('window.location="http://www.google.com"', 3000);
//-->
</script>

This is valid XHTML and you need to put this code in between the <head> and </head> tags of your page. The 3000 means the page will redirect in 3000 milliseconds–or 3 seconds, change it to be what you want.

Do you want an instantaneous redirect? Here’s the code (same rules apply as above):

<script type="text/javascript">
<!--
window.location="http://www.google.com"';
//-->
</script>

The address can be relative or absolute. People may have Javascript turned off, so I find a PHP redirect much better.