Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A beginner needs some help

    Hi, I'm javascript beginner and I need some help. Can anybody translate these functions in English?
    I can't find similar examples in books or in the Internet.
    code
    function KeyPress(e,nf) {
    kk=e.which;
    kk ? kk=kk:kk=event.keyCode;
    if (kk==13) {eval("document.forms[0]."+nf+".focus()");e.returnValue=false};
    };
    function KeyPress1(e) {
    kk=e.which;
    kk ? kk=kk:kk=event.keyCode;
    if (kk==13) {fsubmit('login');e.returnValue=false};
    };
    /code
    Thank you......
    Last edited by petergr; 03-22-2004 at 01:37 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    function KeyPress(e,nf) { //function "KeyPress" accepting two arguments, "e" and "nf"
      kk = e.which;  //variable "kk" is equal to the charCode of the key "e"
      kk ? kk=kk:kk=event.keyCode;  //looks like a messed up conditional statement
      if (kk==13) {
        eval("document.forms[0]."+nf+".focus()");  //sets focus to the the whatever field "nf" is
        e.returnValue = false;  //suppresses the event that the browser has programmed for this key
      }
    }
    
    function KeyPress1(e) {
      kk=e.which;
      kk ? kk=kk:kk=event.keyCode;
      if (kk==13) {
        fsubmit('login');
        e.returnValue = false;
      }
    }
    I didn't comment the second function because it pretty much deals with the same sort of things. Just so you know, I looked up all of comments I just gave you on the web. Google is my buddy!

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Antoniohawk
    But what the line code kk = e.which /code means?
    What does the word "which" means? I didn't find this word among reserved of javaScript.
    And again, what does the line code kk = event.keyCode /code means? Thank you.....

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I looked for that for practically a half an hour and finally found this site:
    http://www.dansteinman.com/dynduo/en/keystrokes.html

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot for your time, Antoniohawk.
    I was looking for similar information much longer then you with no success.
    Thanks again…..

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hehe... by the way that "messed up conditional statement" can come in handy.

    It's basically a shortcut for an if/then/else statement, called a "ternary operator".

    Here's an example I wrote to determine if someone is pressing a number key, backspace, enter, or delete:

    Code:
    <html>
    	<head>
    		<title>isNumericKey() Test</title>
    <script type="text/javascript">
    <!--
    function isNumericKey(e)
    {
    	var k = document.all ? e.keyCode : e.which;
    	return ((k > 47 && k < 58) || k == 8 || k == 0 || k == 13);
    }
    // -->
    </script>
    	</head>
    	<body>
    		<form id="form1" action="javascript://" method="post">
    			<input type="text" name="txtField1" value="" onkeypress="return isNumericKey(event)" />
    		</form>
    	</body>
    </html>
    http://www.mredkj.com/tutorials/refe...s_ternary.html
    http://cplus.about.com/library/gloss...ryoperator.htm
    http://www.devdaily.com/java/edu/pj/pj010018/
    Last edited by whammy; 03-22-2004 at 05:30 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So there is nothing "messed up" about this line?

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, as you can see from the links I posted in my edited post above, many languages use the same syntax as a one-line shortcut for an if/else statement.

    I should mention that I agree with Antonio Hawk - Google is my buddy too.

    It should be any programmer's buddy. I've had to program in languages I've never dealt with before, and have no books on (i.e. JSP), and Google can really be a life saver in those situations.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Whammy.
    As far as I understand. there are different ways in which ME and Netscape handle keystroke.... Is it a common practice (I'm new to javaScript) for this approach in coding : If this is ME do this piece of code else do that?

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah. It is. I'm assuming by "ME" you mean Internet Explorer.

    That's what the

    document.all ? dothis : dothat;

    does. The main problem is that you have browsers like Internet Explorer which have proprietary coding (they don't follow standards recommendations, etc.).

    This situation has actually improved in the last couple of years due to a lot of browsers coming out that have great standards support, for instance Mozilla and Mozilla FireFox.

    http://www.mozilla.org

    After using Mozilla Firefox (even regular Mozilla), I only use Internet Explorer to test my web pages for IE users. Mozilla is by far the best browser out there, and I'm sure most of the experienced people on this forum would agree with me.

    I personally like Mozilla Firefox even better.
    Last edited by whammy; 03-22-2004 at 04:39 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #11
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK. I'll try Mozolla. And a "silly" question... What should I do so the examle code stood code: body of code - bottom line - further comments.....

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure I understand what you are asking.
    Last edited by whammy; 03-22-2004 at 04:49 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #13
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, the way Antoniohawk showed my code
    code:
    line
    body of code
    bottom line

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh... click here.

    [code]Code here[/code]
    Last edited by whammy; 03-22-2004 at 04:55 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #15
    New Coder
    Join Date
    Mar 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Whammy.....


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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