want to ask about ascii in javascript

Discussion in 'JavaScript' started by sela cullens, Apr 30, 2009.

  1. #1
    hi,,
    I have tried to wrote code with ascii,I'm still not understand declared ascii in javascript.so this why I'm in this forum.to know the answer.

    I have one field, if I input field "05/01/" then I press "tab" from keyboard.I get year from this year, so the value in a field will be "05/01/2009".

    
    <script language="javascript">
    function GetYear(){
       var now=new Date();
       year=now.getFullYear();
       if(document.formname.field.value.length==6){
            if(ascii==9){
                field.value=field.value+year;
            }
        }
    }
    </script>
    
    Code (markup):
    I don't know how to declare it in javascript. and I'm still dont know this function where I must put. in onKeyUp or onKeyPress or onKeyDown or onBlur??

    if anyone know the answer, please give me the answer and give me a suggestion where I must put that function or any suggestion.

    thanks

    sela
     
    sela cullens, Apr 30, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    erm, i'd use onkeyup (keypress released).

    essentially, something like this (not tested but ought to be fine):
    
    var insertDate = function() {
        // code here to add the date
    };
    
    window.onload = function() {
         document.getElementById("dateid").onkeyup = function(e) {
            if (e.keycode == 9 | e.which == 9) { // old netscape based browsers use .which
                // do something with tab.
                insertDate();
            }
            // you probably need to handle shift+tab also - check e.shiftKey
        };
    
        document.getElementById("dateid").onblur = function() {
            insertDate(); // they can use mouse to unfocus and not tab... 
        };
    };
    PHP:
     
    dimitar christoff, May 1, 2009 IP
  3. sela cullens

    sela cullens Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I will try it.
    Thanks for your help (^_^)
     
    sela cullens, May 1, 2009 IP