Simple JavaScript Clock
Simple JavaScript Clock
<SCRIPT Language=”JavaScript”>
<!– hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = “” + ((hour > 12) ? hour – 12 : hour)
if(hour==0) temp = “12″
if(temp.length==1) temp = ” ” + temp
temp += ((minute < 10) ? “:0″ : “:”) + minute
temp += ((second < 10) ? “:0″ : “:”) + second
temp += (hour >= 12) ? ” PM” : ” AM”
document.clockForm.digits.value = temp
id = setTimeout(“jsClock()”,1000)
}
//–>
</SCRIPT>
<BODY ONLOAD=”jsClock()”>
<FORM NAME=”clockForm”>
<FONT face=”Courier New,Courier” size=3><B>
<INPUT TYPE=”text” NAME=”digits” SIZE=11 VALUE=”Loading”></B>
</FONT>
</FORM>
Javascript Replace new Lines
var varNotes = varNotes.replace(
// Replace out the new line character.
new RegExp( “\n“, “g” ),
// Put in … so we can see a visual representation of where
// the new line characters were replaced out.
“<br>”
);
JavaScript xsd validation and examples
<SCRIPT LANGUAGE=”JavaScript”>
var sOutput = validateFile(“sc-valid.xml”);
alert(sOutput);
function validateFile(strFile)
{
// Create a schema cache and add books.xsd to it.
var xs = new ActiveXObject(“MSXML2.XMLSchemaCache.4.0″);
xs.add(“urn:books”, “sc.xsd”);
// Create an XML DOMDocument object.
var xd = new ActiveXObject(“MSXML2.DOMDocument.4.0″);
// Assign the schema cache to the DOMDocument’s
// schemas collection.
xd.schemas = xs;
// Load books.xml as the DOM document.
xd.async = false;
xd.validateOnParse = true;
xd.resolveExternals = true;
xd.load(strFile);
// Return validation results in message to the user.
if (xd.parseError.errorCode != 0)
{
return(“Validation failed on ” + strFile +
“n=====================” +
“nReason: ” + xd.parseError.reason +
“nSource: ” + xd.parseError.srcText +
“nLine: ” + xd.parseError.line + “n”);
}
else
return(“Validation succeeded for ” + strFile +
“n======================n” +
xd.xml + “n”);
}
</SCRIPT>
=========================
File: sc-valid.xml
——————-
<?xml version=”1.0″?>
<x:catalog xmlns:x=”urn:books”>
<book id=”bk101″>
<author>Gambardella, Matthew</author>
<title>XML Developer’s Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
</x:catalog>
—————————–
File: sc.xsd
—————————–
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
targetNamespace=”urn:books”
xmlns:b=”urn:books”>
<xsd:element name=”catalog” type=”b:CatalogData”/>
<xsd:complexType name=”CatalogData”>
<xsd:sequence>
<xsd:element name=”book”
type=”b:bookdata”
minOccurs=”0″
maxOccurs=”unbounded”/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name=”bookdata”>
<xsd:sequence>
<xsd:element name=”author” type=”xsd:string”/>
<xsd:element name=”title” type=”xsd:string”/>
<xsd:element name=”genre” type=”xsd:string”/>
<xsd:element name=”price” type=”xsd:float”/>
<xsd:element name=”publish_date” type=”xsd:date”/>
<xsd:element name=”description” type=”xsd:string”/>
</xsd:sequence>
<xsd:attribute name=”id” type=”xsd:string”/>
</xsd:complexType>
</xsd:schema>





