i try this scripty which is supposed to make layer visible just next to the text field where the user didnt enter anythings( like in yahoo forms), when i runs it in the browser it dooesn not give me any errors message.
<html>
<head>
<title>i will try a form validation</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”javascript” type=”text/javascript”>
function validate(){
SubmitOk=”true”;
if (document.form0.txtname.length==0){
switchDiv(nameDiv);
SubmitOk=”false”;
}
if (document.form0.txtpass.length==0){
switchDiv(password);
SubmitOk=”false”;
}
if (submitOk=”false”){
return false}
}
function switchDiv(div_id)
{
var style_sheet = getStyleObject(div_id);
if (style_sheet)
{
hideAll();
changeObjectVisibility(div_id, “visible”);
}
else
{
alert(“sorry, this only works in browsers that do Dynamic HTML”);
}
}
function changeObjectVisibility(objectId, newVisibility) {
// first get the object’s stylesheet
var styleObject = getStyleObject(objectId);
// then if we find a stylesheet, set its visibility
// as requested
//
if (styleObject) {
styleObject.visibility = newVisibility;
return true;
} else {
return false;
}
}
function getStyleObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
}
else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
}
else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
} else {
return false;
}
}
</script>
</head>
<body>
<form name=”form0″ onSubmit=”return validate()”>
<table bgcolor=”#0099CC” border=”1″ align=”left”>
<tr>
<td>
Name:
</td>
<td>
<input type=”text” name=”txtname” value=””>
</td>
<td>
<div id=”nameDiv” style=”position:absolute; background-color:#FFCC33; font:adobe calson pro; font-size:12px; z-index:2; left: 218px; top: 29px; height: 19px; width: 129px; visibility:hidden;”><strong> Please enter your name</strong>
</div>
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<input type=”text” name=”txtpass” value=””>
</td>
<td>
<div id=”password” style=”position:absolute; background-color:#FFCC33; font:adobe calson pro; font-size:12px; z-index:2; left: 218px; top: 29px; height: 19px; width: 129px; visibility:hidden;”><strong> Please enter your password</strong>
</div>
</td>
</tr>
<tr>
<td>
<input name=”Submit” type=”submit” value=”Submit”>
</td>
</tr>
</table
>
</form>
</body>
</html>