/    Sign up×
Community /Pin to ProfileBookmark

problem with layer in jscript

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>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Apr 03.2006 — You are passing a variable ot a string here: switchDiv(password);

put some quotes around password

Eric
Copy linkTweet thisAlerts:
@raymon2683authorApr 04.2006 — here " password" is the Id of the DIV element and it 's suppose to be passed .

thank i''ll try
Copy linkTweet thisAlerts:
@A1ien51Apr 04.2006 — here " password" is the Id of the DIV element and it 's suppose to be passed .

thank i''ll try[/QUOTE]


Hence why I said you need to put quotes around it. Without queotes you are syaing that you are declaring it somewhere in the page. aka

var password = "someString";

You understand?

Eric
×

Success!

Help @raymon2683 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...