Results 1 to 7 of 7

Thread: prompt with multiple inputs - headache

  1. #1
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default prompt with multiple inputs - headache

    hi gang.

    im trying to execute a prompt in javascript that contains 2 input fields.

    1. is login
    2. is password

    sounds easy enough right?

    well i've been researching this all day and all i find is that you can only check one prompt input at a time.

    additonally if you want 2 fields to check - it seems that people create their own prompt FORM to do it.

    what i want to know is if there is a way for the browser API to let me have 2 fields for input rather than having to create a page for it.

    if anyone has any advice on this it'd be greatly appreciated.

    Please bear in mind i want the browser to generate the popup verification with TWO fields (like a prompt with 2 fields SIMULTANEOUSLY) not 1 after the other (as is seen here) and i DO NOT want to have to use a second (loaded in) webpage to do it. It really needs to be done by the browser.

    my source looks like this right now:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>TBG Portal</title>

    <script language="JavaScript">
    <!--hide


    var password;
    var login;


    <!-- case sensitive buffers --!>
    var log1="demo";
    var log2="DEMO";
    var log3="Demo";

    var pass1="password";
    var pass2="PASSWORD";
    var pass3="Password";

    password=prompt('Password',' ');
    login = prompt ('login:', ' ');

    if ((password==pass1 || password==pass2 || password==pass3) && (login==log1 || login==log2 || login==log3))
    alert('Password and Login Accepted: Click OK to enter'); <!-- this allows page to continue loading--!>
    else
    {
    alert('Password or Login Incorrect: Click OK to try again');
    window.location="entry.html"; <!-- this reloads page lockout --!>
    }

    //-->
    </script>
    </head>

    <body>
    VIEWING THIS PAGE. LOCKED OUT TIL PASS LOG CORRECT.
    </body>
    </html>

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    I hope this page isn't supposed to be secure? your javascript would be viewable to anyone, thus knowing the correct username / password to access the site. also you shouldn't be using XHTML because it is not widely supported, most notably Internet Explorer, which regretfully is still the most popular browser platform. Look into the HTML 4.01 Strict DOCTYPE.

    you also have 3 "usernames" and 3 "passwords" in different cases. If you do not care what the case is, you should be using a regular expression, rather than checking each value like you are. PaSSworD is another "valid" case-insensitive value as you are writing it.

    now as for your question about a double "prompt" you would need to create a custom module that would mimic the actions of a javascript prompt. this isnt the best script, you can check out a customizable prompt script at http://javascript.internet.com/text-...pt-prompt.html

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    here is the regexp for you so it is case insensitive. also i would look into a modal instead of a prompt :
    Code:
    pass=/^password$/i;
    log=/^demo$/i;
    and just use:
    Code:
    if(password.match(pass)!=null && login.match(log)!=null)
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by Master_script_maker View Post
    here is the regexp for you so it is case insensitive. also i would look into a modal instead of a prompt :
    Code:
    pass=/^password$/i;
    log=/^demo$/i;
    and just use:
    Code:
    if(password.match(pass)!=null && login.match(log)!=null)
    Yes i would look into the modal... that is what the link was to.

    Its good coding practice to encapsulate (wrap) your element values in quotation marks, and dont forget to declare them as well. Again not necessary in javascript because it is a "very" loosely typed language, but its good general coding practice

    Code:
    var pass = "/^password$/i";
    var log = "/^demo$/i";

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    here is the regexp for you so it is case insensitive.
    Regexes are expensive -- don't use them when there's a better solution available (like converting the value to lower-case before checking [with .toLowerCase()], in this case).
    Its good coding practice to encapsulate (wrap) your element values in quotation marks, and dont forget to declare them as well. Again not necessary in javascript because it is a "very" loosely typed language, but its good general coding practice
    You're wrong -- this is a regular expression literal syntax. Any value between two slashes, with optional alphabetic switches at the end, is a regular expression literal. /^password$/i is (more or less) equivalent to (new RegExp("^password$", "i")). Using var to make sure they're treated as variables is a good idea, though.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by Twey View Post
    Regexes are expensive -- don't use them when there's a better solution available (like converting the value to lower-case before checking [with .toLowerCase()], in this case).
    and by expensive you mean time consuming? I do agree that you should avoid using regular expressions whenever possible.

    You're wrong -- this is a regular expression literal syntax. Any value between two slashes, with optional alphabetic switches at the end, is a regular expression literal. /^password$/i is (more or less) equivalent to (new RegExp("^password$", "i")). Using var to make sure they're treated as variables is a good idea, though.
    wont that be treated as
    Code:
    password.match(/^password$/i);

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    and by expensive you mean time consuming?
    Very much so, for some expressions.
    wont that be treated as
    Eh?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •