Web Analytics Made Easy -
StatCounter Doing an IF and ELSE in html - CodingForum

Announcement

Collapse
No announcement yet.

Doing an IF and ELSE in html

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Doing an IF and ELSE in html

    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 ([email protected]) -->

    <!-- 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>

  • #2
    Code:
    window.location = ......
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

    Comment


    • #3
      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.

      Comment


      • #4
        Code:
        <!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 ([email protected])  -->
        
        <!-- 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?
        Last edited by webguy08; Apr 3, 2009, 06:22 PM.

        Comment


        • #5
          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

          Comment


          • #6
            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".
            Is IE9 a modern browser?
            IE9 is at least 2 years behind the modern web.

            Comment

            Working...
            X