/    Sign up×
Community /Pin to ProfileBookmark

Send set of eyes- what am I missing – Thx

I am simply trying to “hard code” a password and userID for a user simulation demo. I must be missing something simple, but can’t find it. I’m a new JavaScripter and would appreciate you help. Thx, annrico1

<script type=”text/javascript”>
<!–HIDE FROM INCOMPATIBLE BROWSERS
var userID;
var password;

function login_onsubmit() {
if (document.loginForm.userID.value == “demo” && document.loginForm.password.value == “good”)
document.write(“Login complete. Click the Dashboard link.”);
}
else {
document.write(“Your UserID or Password are incorrect. Email the System Administrator for assistance by clicking <a href=”mailto:[email protected]“>here.</a>”);
}

// STOP HIDING FROM INCOMPATIBLE BROWERS –>
</script>
</head>

<body>

<div id=”NavBar”>
<table bgcolor=”#cccccc”>
<tr bgcolor=”#ffffff”><td>Organization: Goodtimes</td></tr>
<tr bgcolor=”#cccccc”><td><a href=”Dashboard.htm”>Dashboard</a></td></tr>
</table>
</div><!– end NavBar –>

<div id=”header1″>
<p><strong><Management</strong> – Login</p>
</div><!–end div header1–>

<div id=”loginForm”>
<h2 align=”center”>PLEASE LOGIN</h2>
<form action=”” name=”loginForm” onsubmit=”return login_onsubmit();”>
<table>
<tr>
<td align=”right”>User ID:</td>
<td><input type=”text” name=”userID” value=”” size=”20″/></td>
</tr>

<tr>
<td align=”right”>Password:</td>
<td><input type=”text” name=”password” value=”” size=”20″ /></td>
</tr>

<tr>
<td colspan=”2″ align=”right”>
<div align=”center”>
<input type=”submit” value=”SUBMIT” />
</div>
</td>
</tr>
</table>
</form>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemSep 10.2006 — 
if (document.loginForm.userID.value == "demo" && document.loginForm.password.value == "good")

document.write("Login complete. Click the Dashboard link.");

}

else {

document.write("Your UserID or Password are incorrect. Email the System Administrator for assistance by clicking <a href="mailto:[email protected]">here.</a>");

}
[/QUOTE]
You're missing the fact that [I]document.write[/I] cannot be called after a document has loaded.
Copy linkTweet thisAlerts:
@Mr_JSep 10.2006 — You could try something like this

[code=php]<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<script type="text/javascript">
<!--
var userID;
var password;

function login_onsubmit() {
if (document.loginForm.userID.value == "demo" && document.loginForm.password.value == "good"){
document.getElementById("tempdiv").innerHTML="Login complete. Click the Dashboard link."
}
else {
document.getElementById("tempdiv").innerHTML="Your UserID or Password are incorrect. Email the System Administrator for assistance by clicking <a href="mailto:[email protected]">here.</a>"
}

return false

}

// -->
</script>

</HEAD>
<BODY>

<div id="NavBar">
<table bgcolor="#cccccc">
<tr bgcolor="#ffffff"><td>Organization: Goodtimes</td></tr>
<tr bgcolor="#cccccc"><td><a href="Dashboard.htm">Dashboard</a></td></tr>
</table>
</div><!-- end NavBar -->

<div id="header1">
<p><strong><Management</strong> - Login</p>
</div><!--end div header1-->

<div id="loginForm">
<h2 align="center">PLEASE LOGIN</h2>

<h3 id="tempdiv">&nbsp;</h3>

<form action="" name="loginForm" onsubmit="return login_onsubmit();">
<table>
<tr>
<td align="right">User ID:</td>
<td><input type="text" name="userID" value="" size="20"/></td>
</tr>

<tr>
<td align="right">Password:</td>
<td><input type="text" name="password" value="" size="20" /></td>
</tr>

<tr>
<td colspan="2" align="right">
<div align="center">
<input type="submit" value="SUBMIT" />
</div>
</td>
</tr>
</table>
</form>

</BODY>
</HTML>[/code]
Copy linkTweet thisAlerts:
@annrico1authorSep 10.2006 — Arty & Mr J,

Thank you both so much. This solved my problem in 2 different ways, and taught me some new things. thx again, annrico1
×

Success!

Help @annrico1 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.18,
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,
)...