Javascript login

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GreenBayFan

    #1

    Javascript login

    Hello, I am a computer science major. I have had HTML and Java, but not any
    JavaScript. I know they are similar, but there seem to be a lot of functions
    and methods I am not familiar with. Plus I don't have a good understanding
    of what Java can do within the web environment. (My Java classes
    concentrated on console based applications.)

    What I want is a simple Java Login box for "Apartment Number" that takes
    that value and assigns it to a variable, such as "apartment" . I would like
    to take the value of that variable, for example, 1555-7 and have the
    computer load the webpage "1555-7.html"; preferrably within a frame called
    Body. I would also like to do this without a popup, but an actual text box
    within the webpage. Any help would be appreciate. I have seen various
    methods of loading a new webpage, but don't which one to use. I have also
    looked through the free scripts, and none of them seem to work for what I
    want. They are either popups, or do too many complicated encryption
    functions. Any help would be appreciated. I think I have a good idea on the
    basic input to variable aspect. But don't have a clue as to how to load a
    webpage using JavaScript.

    P.S. What is the best, most complete source for JavaScript knowledge? (book
    or website) Something that covers all that JavaScript can do.


  • Hal Rosser

    #2
    Re: Javascript login


    "GreenBayFa n" <wdy@panola.com > wrote in message
    news:10tp9vne0p nb71e@corp.supe rnews.com...[color=blue]
    > Hello, I am a computer science major. I have had HTML and Java, but not[/color]
    any[color=blue]
    > JavaScript. I know they are similar, but there seem to be a lot of[/color]
    functions[color=blue]
    > and methods I am not familiar with. Plus I don't have a good understanding
    > of what Java can do within the web environment. (My Java classes
    > concentrated on console based applications.)
    >
    > What I want is a simple Java Login box for "Apartment Number" that takes
    > that value and assigns it to a variable, such as "apartment" . I would like
    > to take the value of that variable, for example, 1555-7 and have the
    > computer load the webpage "1555-7.html"; preferrably within a frame called
    > Body. I would also like to do this without a popup, but an actual text box
    > within the webpage. Any help would be appreciate. I have seen various
    > methods of loading a new webpage, but don't which one to use. I have also
    > looked through the free scripts, and none of them seem to work for what I
    > want. They are either popups, or do too many complicated encryption
    > functions. Any help would be appreciated. I think I have a good idea on[/color]
    the[color=blue]
    > basic input to variable aspect. But don't have a clue as to how to load a
    > webpage using JavaScript.
    >
    > P.S. What is the best, most complete source for JavaScript knowledge?[/color]
    (book[color=blue]
    > or website) Something that covers all that JavaScript can do.[/color]

    Not sure if you're looking for a Java app, or a JavaScript solution.
    Anyway - www.w3schools.com has a javascript tutorial
    and you can use www.devguru.com for a decent reference
    Netscape (AOL) seems to have abandoned the Javascript community
    -- To go with Java, you'll probably need to work with server-side stuff like
    JSP and servlets.



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.818 / Virus Database: 556 - Release Date: 12/17/2004


    Comment

    • GreenBayFan

      #3
      Re: Javascript login

      Using a free script from the internet, here is what I believe I am looking for: (something similar to this. This is after some editing.)

      <form>
      <p>Enter your apartment number :
      <input type="text" name="Apartment ">
      </p>
      <input type="button" value="Log In" name="Submit" onclick=javascr ipt:validate(Ap artment.value> //Not sure about javascript:vali date
      </p>
      </form>

      <script language = "javascript ">
      function validate(Apartm ent)
      {
      if (Apartment=1555-7) //Or should that be '1555-7'?
      load('1555-7.html');
      else if (Apartment=1555-6)
      {
      load('1555-6.html');
      }
      else if (Apartment=1555-5)
      {
      load('1555-5.html')
      }
      }
      function load(url)
      {
      location.href=u rl;
      }
      }
      </script>

      Like I said, I don't have any experience in this at all. (Except for Java experience.) This seems like it would work, but it doesn't load the webpage after clicking the Submit button. (Just doesn't load the site). Any help would be appreciated. Also, I am not one to take credit for other people's work. I deleted the copyright information for readability. So here is the information:

      Script by Anubhav Misra (anubhav_misra@ hotmail.com)
      Submitted to JavaScript Kit (http://javascriptkit.com)
      For this and 400+ free scripts, visit http://javascriptkit.com
      This free script provided by JavaScript Kit




      "GreenBayFa n" <wdy@panola.com > wrote in message news:10tp9vne0p nb71e@corp.supe rnews.com...[color=blue]
      > Hello, I am a computer science major. I have had HTML and Java, but not any
      > JavaScript. I know they are similar, but there seem to be a lot of functions
      > and methods I am not familiar with. Plus I don't have a good understanding
      > of what Java can do within the web environment. (My Java classes
      > concentrated on console based applications.)
      >
      > What I want is a simple Java Login box for "Apartment Number" that takes
      > that value and assigns it to a variable, such as "apartment" . I would like
      > to take the value of that variable, for example, 1555-7 and have the
      > computer load the webpage "1555-7.html"; preferrably within a frame called
      > Body. I would also like to do this without a popup, but an actual text box
      > within the webpage. Any help would be appreciate. I have seen various
      > methods of loading a new webpage, but don't which one to use. I have also
      > looked through the free scripts, and none of them seem to work for what I
      > want. They are either popups, or do too many complicated encryption
      > functions. Any help would be appreciated. I think I have a good idea on the
      > basic input to variable aspect. But don't have a clue as to how to load a
      > webpage using JavaScript.
      >
      > P.S. What is the best, most complete source for JavaScript knowledge? (book
      > or website) Something that covers all that JavaScript can do.
      >
      >[/color]

      Comment

      • Ved Antani

        #4
        Javascript Error only with MacOS 9 + IE 5

        Hi,

        I have a strange problem. I have a script that runs perfectly well on
        Win+IE5, but fails in Mac OS 9+IE5.

        The following assignment is used in submitRequest() function :

        var result= allForms["RESULT_FOR M"][0];

        This thing works fine in Win+IE5, but in MacOS9+IE 5 we get the
        following JS error : allForms.RESULT _FORM.0 is not an object.

        I can not understand why this thing is happening.

        I would appreciate if you can give some guidance.

        --Ved Antani

        Comment

        • RobG

          #5
          Re: Javascript Error only with MacOS 9 + IE 5

          Ved Antani wrote:[color=blue]
          > Hi,
          >
          > I have a strange problem. I have a script that runs perfectly well on
          > Win+IE5, but fails in Mac OS 9+IE5.
          >
          > The following assignment is used in submitRequest() function :
          >
          > var result= allForms["RESULT_FOR M"][0];
          >
          > This thing works fine in Win+IE5, but in MacOS9+IE 5 we get the
          > following JS error : allForms.RESULT _FORM.0 is not an object.[/color]

          We need to see a little more code. Can you show how you create
          "allForms"? If you are using:

          var allForms = document.forms;

          Then allForms will be a collection of all the forms. If one of the
          forms is called "RESULT_FOR M", then:

          var result = allForms["RESULT_FOR M"][0]

          will create a reference to the first element in the form. Following is
          a trivial case that works in IE 5 on OS 9 and IE 5.2 on OS X:

          <html><head>
          <title>IE play</title>
          <script type="text/javascript">
          function sayForms() {
          var allForms = document.forms;
          var result = allForms["RESULT_FOR M"][0];
          alert(result.no deName);
          }
          </script>

          </head><body>
          <form name="form1" action="">
          <input type="text" value="in form 1">
          </form>
          <br>
          <form name="RESULT_FO RM" action="">
          <input type="text" value="in RESULT_FORM">
          <input type="button" value="click me" onclick="
          sayForms();
          ">
          </form>
          </body></html>



          --
          Rob

          Comment

          • Yann-Erwan Perio

            #6
            Re: Javascript login

            GreenBayFan wrote:
            [color=blue]
            > Hello, I am a computer science major. I have had HTML and Java, but not any
            > JavaScript. I know they are similar, but there seem to be a lot of functions
            > and methods I am not familiar with.[/color]

            Don't say they're similar, they have in fact nothing in common (except
            maybe some syntax grammar, like C-like control structures).

            Javascript is an interpreted language, which can be embedded in various
            host environments (one of them being browsers); it can be coded in a
            procedural, object-oriented or functional flavour; it is a remarkably
            expressive language.
            [color=blue]
            > What I want is a simple Java Login box[/color]

            I assume you mean javascript!
            [color=blue]
            > for "Apartment Number" that takes
            > that value and assigns it to a variable, such as "apartment" . I would like
            > to take the value of that variable, for example, 1555-7 and have the
            > computer load the webpage "1555-7.html"; preferrably within a frame called
            > Body.[/color]

            <form action=""
            method="post"
            target="Body"
            onsubmit="retur n loadRoom(this)" >
            <input type="text" name="roomNumbe r">
            <input type="submit" value="Go to the room!">
            </form>

            <iframe name="Body"></iframe>

            <script type="text/javascript">
            function loadRoom(frm){
            return (
            frm.action=
            frm.elements["roomNumber "].value.replace(/\.html?$/i,"")+".html"
            ).length>5;
            }
            </script>

            .... is probably the simplest, although you'll lack acceptable fallback
            for instance in case of 404 or no-js user agents, which lead me to think
            this should be done server-side.


            Regards,
            Yep.

            Comment

            • RobG

              #7
              Re: Javascript Error only with MacOS 9 + IE 5

              RobG wrote:
              [...][color=blue]
              >
              > var result = allForms["RESULT_FOR M"][0]
              >
              > will create a reference to the first element in the form. Following is
              > a trivial case that works in IE 5 on OS 9 and IE 5.2 on OS X:[/color]

              Forgot to add that if you want the value of the element (presuming it
              is a text input) then use:

              var result = allForms["RESULT_FOR M"][0].value;


              --
              Rob

              Comment

              • Grant Wagner

                #8
                Re: Javascript login

                > "GreenBayFa n" <wdy@panola.com > wrote in message
                news:10tpbsmrg9 kslda@corp.supe rnews.com...

                Your code was such a horrible mess I completely re-wrote it:

                <form action="" method="GET" onsubmit="retur n go(this);">
                <p>Enter your apartment number: <input type="text" name="Apartment "></p>
                <p><input type="submit" value="Log In" name="Submit"></p>
                </form>
                <script type="text/javascript">
                function go(f) {
                var a = f.elements['Apartment'];
                switch(a) {
                case '1555-5':
                case '1555-6':
                case '1555-7':
                f.target = a + '.html';
                return true;
                break;
                }
                return false;
                }
                </script>

                It is trivially easy to get around by looking at the source code (and
                no, you can't hide the JavaScript source from the person). And it
                provides no way to stop the user from simply entering another apartment
                number, or for that matter, typing
                http://yourserver/{someapartment# }.html into their Web browser's address
                bar.

                --
                Grant Wagner <gwagner@agrico reunited.com>
                comp.lang.javas cript FAQ - http://jibbering.com/faq


                Comment

                • Ved Antani

                  #9
                  Re: Javascript Error only with MacOS 9 + IE 5

                  Hi Rob, Thanks a lot for your help.
                  The major code is like this

                  In the HTML file I have the following JS Functions
                  --------------------------------------------------
                  /* Initializes the 'allForms' arry */
                  function initialize(doc)
                  {
                  top.initDocumen t(doc);
                  }

                  function submitForm(){
                  top.submitReque st("aaa",
                  url,
                  action,
                  func,
                  "",
                  new Array(""),
                  "_top");

                  }
                  ....
                  /* Later I have the following Form in the same HTML */
                  /* The Hidden input are null and haveing name as null too will this
                  create any problems ? */

                  <form name="RESULT_FO RM" method=POST>
                  <input type="hidden" name="" value="">
                  <input type="hidden" name="" value="">
                  <input type="hidden" name="" value="">
                  <input type="hidden" name="" value="">
                  <input type="hidden" name="" value="">
                  </form>
                  ---------------------------------------------------------------------
                  The function 'initDocument() ' creates the allForms array of forms and
                  the 'submitRequest( )' method submits the record. While submitting the
                  form, we get the error in IE5+MacOS 9
                  ---------------------------------------------------------------------
                  Code of submitRequest() is something like :
                  ---------------------------------------------------------------------
                  function submitRequest( url, //Url to submit to
                  generalData, //Some other data
                  formNames, //Forms to be submitted
                  target,
                  method) // request method for form.
                  {

                  //We get the form here

                  var result= allForms["POR_RESULT_FOR M"][0];

                  result.action= url;
                  result.target= target;
                  result.method= ((method=="GET" || target=="por_ma in") ? "GET" : "POST");
                  //we populate all the elements of the forms to be submitted to
                  //'result' object and then submit it
                  //Probably the point of error
                  result.submit() ;
                  }
                  ---------------------------------------------------------------------
                  I think the problem is with the syntax of the last time 'result.submit( );'
                  This works well in IE 5+ Win and fails saying
                  'RESULT_FORM.0 is not an object'


                  Please help.

                  --Ved




                  RobG wrote:[color=blue]
                  > RobG wrote:
                  > [...]
                  >[color=green]
                  >>
                  >> var result = allForms["RESULT_FOR M"][0]
                  >>
                  >> will create a reference to the first element in the form. Following is
                  >> a trivial case that works in IE 5 on OS 9 and IE 5.2 on OS X:[/color]
                  >
                  >
                  > Forgot to add that if you want the value of the element (presuming it
                  > is a text input) then use:
                  >
                  > var result = allForms["RESULT_FOR M"][0].value;
                  >
                  >[/color]

                  Comment

                  • Ved Antani

                    #10
                    Re: Javascript Error only with MacOS 9 + IE 5

                    RobG wrote:[color=blue]
                    > Ved Antani wrote:
                    >[color=green]
                    >> Hi,
                    >>
                    >> I have a strange problem. I have a script that runs perfectly well on
                    >> Win+IE5, but fails in Mac OS 9+IE5.
                    >>
                    >> The following assignment is used in submitRequest() function :
                    >>
                    >> var result= allForms["RESULT_FOR M"][0];
                    >>
                    >> This thing works fine in Win+IE5, but in MacOS9+IE 5 we get the
                    >> following JS error : allForms.RESULT _FORM.0 is not an object.[/color]
                    >
                    >
                    > We need to see a little more code. Can you show how you create
                    > "allForms"? If you are using:
                    >
                    > var allForms = document.forms;
                    >
                    > Then allForms will be a collection of all the forms. If one of the
                    > forms is called "RESULT_FOR M", then:
                    >
                    > var result = allForms["RESULT_FOR M"][0]
                    >
                    > will create a reference to the first element in the form. Following is
                    > a trivial case that works in IE 5 on OS 9 and IE 5.2 on OS X:
                    >
                    > <html><head>
                    > <title>IE play</title>
                    > <script type="text/javascript">
                    > function sayForms() {
                    > var allForms = document.forms;
                    > var result = allForms["RESULT_FOR M"][0];
                    > alert(result.no deName);
                    > }
                    > </script>
                    >
                    > </head><body>
                    > <form name="form1" action="">
                    > <input type="text" value="in form 1">
                    > </form>
                    > <br>
                    > <form name="RESULT_FO RM" action="">
                    > <input type="text" value="in RESULT_FORM">
                    > <input type="button" value="click me" onclick="
                    > sayForms();
                    > ">
                    > </form>
                    > </body></html>
                    >
                    >
                    >[/color]
                    Small Correction in the line var result = allForms["POR_RESULT_FOR M"][0]
                    is actually var result = allForms["RESULT_FOR M"][0]

                    Comment

                    • GreenBayFan

                      #11
                      Re: Javascript login

                      First let me thank you for your help. However, I never said it was "my"
                      code. Secondly, Javascript is something I am not familiar with, which I
                      stated. (Other than it's similarity to Java) Third, this ain't Fort Knox. I
                      am not even thinking of security right now.

                      However I must say that your code is the most efficient, as I have seen some
                      truly over the top examples, to do simple things.


                      "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
                      news:PegDd.60$3 d3.520@news2.mt s.net...[color=blue][color=green]
                      >> "GreenBayFa n" <wdy@panola.com > wrote in message[/color]
                      > news:10tpbsmrg9 kslda@corp.supe rnews.com...
                      >
                      > Your code was such a horrible mess I completely re-wrote it:
                      >
                      > <form action="" method="GET" onsubmit="retur n go(this);">
                      > <p>Enter your apartment number: <input type="text" name="Apartment "></p>
                      > <p><input type="submit" value="Log In" name="Submit"></p>
                      > </form>
                      > <script type="text/javascript">
                      > function go(f) {
                      > var a = f.elements['Apartment'];
                      > switch(a) {
                      > case '1555-5':
                      > case '1555-6':
                      > case '1555-7':
                      > f.target = a + '.html';
                      > return true;
                      > break;
                      > }
                      > return false;
                      > }
                      > </script>
                      >
                      > It is trivially easy to get around by looking at the source code (and
                      > no, you can't hide the JavaScript source from the person). And it
                      > provides no way to stop the user from simply entering another apartment
                      > number, or for that matter, typing
                      > http://yourserver/{someapartment# }.html into their Web browser's address
                      > bar.
                      >
                      > --
                      > Grant Wagner <gwagner@agrico reunited.com>
                      > comp.lang.javas cript FAQ - http://jibbering.com/faq
                      >
                      >[/color]


                      Comment

                      • GreenBayFan

                        #12
                        Re: Javascript login

                        On second though, your code isn't working. Think I will stick with one of
                        the free scripts I got off the internet. At least it worked.

                        Thanks anyway.

                        "GreenBayFa n" <wdy@panola.com > wrote in message
                        news:10tu9bs2kr 3tra0@corp.supe rnews.com...[color=blue]
                        > First let me thank you for your help. However, I never said it was "my"
                        > code. Secondly, Javascript is something I am not familiar with, which I
                        > stated. (Other than it's similarity to Java) Third, this ain't Fort Knox.
                        > I am not even thinking of security right now.
                        >
                        > However I must say that your code is the most efficient, as I have seen
                        > some truly over the top examples, to do simple things.
                        >
                        >
                        > "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
                        > news:PegDd.60$3 d3.520@news2.mt s.net...[color=green][color=darkred]
                        >>> "GreenBayFa n" <wdy@panola.com > wrote in message[/color]
                        >> news:10tpbsmrg9 kslda@corp.supe rnews.com...
                        >>
                        >> Your code was such a horrible mess I completely re-wrote it:
                        >>
                        >> <form action="" method="GET" onsubmit="retur n go(this);">
                        >> <p>Enter your apartment number: <input type="text" name="Apartment "></p>
                        >> <p><input type="submit" value="Log In" name="Submit"></p>
                        >> </form>
                        >> <script type="text/javascript">
                        >> function go(f) {
                        >> var a = f.elements['Apartment'];
                        >> switch(a) {
                        >> case '1555-5':
                        >> case '1555-6':
                        >> case '1555-7':
                        >> f.target = a + '.html';
                        >> return true;
                        >> break;
                        >> }
                        >> return false;
                        >> }
                        >> </script>
                        >>
                        >> It is trivially easy to get around by looking at the source code (and
                        >> no, you can't hide the JavaScript source from the person). And it
                        >> provides no way to stop the user from simply entering another apartment
                        >> number, or for that matter, typing
                        >> http://yourserver/{someapartment# }.html into their Web browser's address
                        >> bar.
                        >>
                        >> --
                        >> Grant Wagner <gwagner@agrico reunited.com>
                        >> comp.lang.javas cript FAQ - http://jibbering.com/faq
                        >>
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        • Got Scripting?

                          #13
                          Re: Javascript login

                          GreenBayFan wrote:[color=blue]
                          >
                          > P.S. What is the best, most complete source for JavaScript knowledge?[/color]
                          (book[color=blue]
                          > or website) Something that covers all that JavaScript can do.[/color]

                          David Flanagan's "Javascript : The Definitive Guide". You can even read
                          it online for free, with a 14-day trial subscription to
                          safari.oreilly. com (lot's of other online books, for as little as $10 a
                          month)

                          Comment

                          Working...