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.
Results 1 to 12 of 12

Thread: onSpaceDown

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    onSpaceDown

    I use this function to move to the next field when a SPACE is pressed.
    Code:
    netscape = "";
    ver = navigator.appVersion;
    len = ver.length;
    for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
    netscape = (ver.charAt(iln+1).toUpperCase() != "C");
    function spaceMover(t) {
    k = (netscape) ? DnEvents.which : window.event.keyCode;
    if (k==32) {
      alert(k);
      t.lastName.focus();
    }
    }
    The problem is I can't "cut" the space from the field because it's added AFTER the function.
    Is there a way to prevent it from adding the space in the first place?

    Thanks

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    space seem a strange choise, uparrow for a text input?
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    it's a first name field
    and a last name field afterwards.

    some people press the space button and start writing their last name before they notice that there is a seperate field for this.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    not trying to be difficult but wont

    value=value.replace(/\s/g,'');

    do
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    As I already said before, I can't manipulate with the lastName field because the space is added AFTER the function is over.

    no matter what i'll do WITHIN the function, the space will be added afterwards.

    I'm looking for a way to PREVENT the space from being added.

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what key event are you using..

    i woud suggest onkeyup.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yeah, but it's not so simple.

    when a user types really fast, sometimes the key is up only after he type another 2-3 keys.

    so it will cause even bigger problem:
    if my name is Shmil Shmilonsky and i type really fast, the name will show:
    [Shmil Sh] [milonsky]

    any idea how to use the onkeydown and prevent space from being shown?
    or maybe another solution using onkeyup?

    Thanks

  • #8
    New Coder
    Join Date
    Oct 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, i got it, i even tested with SendKeys, no one is typing that fast. And it's really quite simple. Use onkeydown. and right after you focus on the lastname field, put:

    Code:
    return false
    and that should take care of it.

  • #9
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    field because the space is added AFTER the function is over
    onblur?
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #10
    New Coder
    Join Date
    Oct 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    on blur wouldn't work because keyevent is still processing. which is why you still get a few chars after you focus the other field. if you return false, then the event is halted, freeing up the process for the focus to occur before the next event is triggered

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    good idea.
    it's working partially:
    after space is pressed - no key is entered within the first field and i'm being passed successfuly to the second field BUT the space is still shown (at the beginning of the second field).

    I can't explain it. don't know why and how to solve it.

  • #12
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    please help.
    it has to have a solution :\

    anyother idea?


  •  

    Posting Permissions

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