...

View Full Version : Doing an IF and ELSE in html



wetwonder
04-03-2009, 10:57 PM
Hi,

I'm trying to figure out the code to have the user enter a simple password, have it verified, and if true redirect to a url. The password is the same for all users. It's doesn't lead to a sensitive place so I don't need encryption or unique passwords, or even user names. So I've gotten this far, but where the password condition is verified, I can't figure out how to code tags to automatically jump to a new url. In other words, where "else return true", I want to call a url to open.

Thanks very much, Dave

............................
Here's some of the code I have so far (AND I INDICATED WHAT I BELIEVE THE PROBLEM SPOT IS BY WRITING A LITERAL IN CAPS AFTER --ELSE RETURN TRUE--):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="TextPad 4.4">
<LINK href="general.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Carey Walker (carey.walker@citicorp.com) -->

<!-- Begin
function checkPw(form) {
pw1 = form.pw1.value;


if (pw1 != "1012cherry") {
alert ("\nPassord incorrect. Please re-enter.")
return false;
}
else return true;

<!-- WHERE PW1 == "1012CHERRY", I WANT TO GO TO HTTP:\\WWW....ETC -->



}



// End -->
</script>

</HEAD>

<BODY Background=../graphics/grayback.jpg>
<center><BR><BR><BR>
<form onSubmit="return checkPw(this)">

<table border=0>
<tr>
<td>Password:</td><td><input type=text name=pw1 size=10></td>
</tr>

<tr>
<td colspan=2 align=center><input type=submit value="Submit!"></td>
</tr>
</table>
</form>

</center>



</BODY>
</HTML>

BubikolRamios
04-03-2009, 11:00 PM
window.location = ......

wetwonder
04-03-2009, 11:07 PM
Thanks, I tried with that but I guess I can't figure out where open.window should be placed b/c I get no response the way I put it in.

webguy08
04-04-2009, 12:01 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="TextPad 4.4">
<LINK href="general.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Carey Walker (carey.walker@citicorp.com) -->

<!-- Begin
function checkPw() {
var pw1 = document.getElementID("passwordField").value;

if (pw1 != "1012cherry") {
alert ("Passord incorrect. Please re-enter.")
}
else if (pw1 == "1012cherry") {
window.open("http://www.example.com");
}

// End -->
</script>

<!-- HTML area: -->

<label for:"password">Password: </label>
<input id="passwordField" type="password" /><br>
<input id="submit" type="button" onclick="checkPw()" />


Try this. Get rid of the table and replace it with the HTML I provided.

Edit: I'm not familiar with HTML 3.2 so I don't know whether my HTML is appropriate. Why not use XHTML 1.0? Or HTML 4.01?

wetwonder
04-04-2009, 02:12 AM
Thanks a great deal webguy. I was able to work with the code you provided to make it all fit. I'm real rusty with HTML, haven't touched it for ten years, so I don't even know about the new formats and versions.
Thanks again,
ww

drhowarddrfine
04-04-2009, 02:13 AM
HTML 3.2 died in the 1990s. wtf is someone doing raising that from the dead again? Use HTML4.01 strict only.

Also, there is no such thing as "language=javascript". Change it to what it's supposed to be, "type=text/javascript".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum