return to site navigation

Java Snippets

Here are a few JavaScripts that we hope you`ll find useful for your own Website :
(we`ll be adding more so check back)
javascript & cookie test - see if your browser has javascript and cookies enabled
and for help resolving possible browser problems.
coloured scroll bars

place in the <head> of your document :-

<STYLE type="text/css">
BODY {scrollbar-3dlight-color:C0C0C0;
scrollbar-arrow-color:red;
scrollbar-base-color:ffffff;
scrollbar-track-color:#ffffff;
scrollbar-darkshadow-color:red;
scrollbar-face-color:#red;
scrollbar-highlight-color:#red;
scrollbar-shadow-color:#986699}
</STYLE>

text link rollovers

place in the <head> of your document :-

<STYLE>
a:link { color:#000000; text-decoration:none}
a:visited { color:#000000; text-decoration:none}
a:hover { color:#FF0000; text-decoration:none; cursor:default}
a:active { color:#000000; text-decoration:none}
</STYLE>

set focus in a form

place in the <head> of your document :-

<script>
function focusonfirst() {
document.form1.name.value = "" ;
document.form1.name.focus () ; }= "" ; }
</script>

and in the body of your document :-

<BODY onLoad= "focusonfirst () ">

where `form1` is the name of your form, and `first` is the name of the first field in your form.

digital clock

place in the <head> of your document :-

<SCRIPT LANGUAGE="JavaScript">
<!--
function showFilled(Value) {
return (Value > 9) ? "" + Value : "0" + Value;
}
function StartClock24() {
TheTime = new Date;
document.clock.showTime.value = showFilled(TheTime.getHours()) + ":" + showFilled(TheTime.getMinutes()) + ":" + showFilled(TheTime.getSeconds());
setTimeout("StartClock24()",1000)
}
//-->
</script>
<style type="text/css">
<!--
.input { border-style: none;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:8pt
}
-->
</style>

and in the body of your document :-

<BODY bgcolor="#FFFFFF" onLoad="StartClock24()">

where you want the clock to appear :-

<form name=clock>
<input type=text name=showTime size=8 class=input>
</form>

mailto: when you add a mailto: link on your website, make it even more professional, by setting the subject of the e-mail ...
use this :-
<a href="mailto:info@yoursite.com?subject=The subject of this email">mail here </a>

 

today`s date

place in the <head> of your document :-

<SCRIPT LANGUAGE="JavaScript">
<!--
function MakeArray(n) {
this.length = n
return this
}
monthNames = new MakeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"
dayNames = new MakeArray(7)
dayNames[1] = "Sunday"
dayNames[2] = "Monday"
dayNames[3] = "Tuesday"
dayNames[4] = "Wednesday"
dayNames[5] = "Thursday"
dayNames[6] = "Friday"
dayNames[7] = "Saturday"

function customDateString() {
currentDate = new Date()
var theDay = dayNames[currentDate.getDay() + 1]
var theMonth = monthNames[currentDate.getMonth() + 1]
msie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
if (msie4) {
var theYear = currentDate.getYear()
}
else {
var theYear = currentDate.getYear() +1900
}
return theDay + ", " + theMonth + " " + currentDate.getDate() + ", " + theYear
}
//-->
</SCRIPT>

where you want the date to appear :-

<SCRIPT LANGUAGE="JavaScript">
document.write(customDateString())
</SCRIPT>


copyright©2008 web-informed.com