www.webdeveloper.com
Results 1 to 3 of 3

Thread: Do I need to unset variable to do this?

  1. #1
    Join Date
    Nov 2008
    Posts
    9

    Do I need to unset variable to do this?

    My JS skill are at the very begining, so I appreciate a bit of a patience.
    -----------------------
    Form has more than one entry field.
    Function is a part of bigger entity (Ajax data call), but problem should not have anything to do with that.
    Function is triggered by onKeyUp event.
    -----------------------
    When user types something into entry field, one image is being replaced by another.
    Eg. user types something, when it is longer that 3 chars, blank image is being replaced by another, eg. "ok" or something.

    For some reason it can be only once and when given entry field will loose focus and user moves to another entry field, showed below function does not work anymore in neither of entry fields.

    Do I need separate functions for every entry field or something?
    Anybody can give me a hint why this image switch dies?

    Regards,

    Jeff

    Code:
    //explanation: inputLen - field input; inputCharLen - chars when reached 
    //image switch triggered; e- event; imagex - image placeholder being switched
    
    
    function gifOn(inputLen, inputCharLen, e, imagex) {
    	
    	var unicode=e.keyCode? e.keyCode : e.charCode
    	
    	if ((inputLen.value.length >= inputCharLen) && (unicode!=9))
    		{ 
    			document[imagex.name].src = "../admin/images/icons/loader.gif";
    
    		} 
    		
    	
    	//gets unwanted keypresses out
    	if ( 
    		(unicode==38) || //arrow up
    		(unicode==40) || //arrow down
    		(unicode==37) || //arrow left 
    		(unicode==39) || //arrow right
    		(unicode==13) || //enter
    		(unicode==27) || //escape
    		(unicode==46) || //delete
    		(unicode==16) || //shift
    		(unicode==17) || //ctrl
    		(unicode==18) || //alt
    		(unicode==93) || //
    		(unicode==91) || //
    		(unicode==20) || //
    		(unicode==223)
    		)
    		{ 
    			document[imagex.name].src = "../admin/images/icons/loader_blanc.gif"; 
    		}
    	
    	if (inputLen.onblur) {  
    			document[imagex.name].src = "../admin/images/icons/loader.gif"; 
    	}
    	
    
    }
    Last edited by jeff7691; 12-31-2008 at 12:57 AM. Reason: typo in code

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,678
    Code:
    <!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" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    //explanation: inputLen - field input; inputCharLen - chars when reached
    //image switch triggered; e- event; imagex - image placeholder being switched
    
    
    
    function gifOn(inputLen, inputCharLen, imagex) {
      var zxce=window.event||arguments.callee.caller.arguments[0];
      var unicode;
      if (zxce.which){ unicode=zxce.which; }
      else { unicode=event.keyCode; }
      var img=document.getElementById(imagex);
    //	var unicode=e.keyCode? e.keyCode : e.charCode
    
    	if ((inputLen.value.length >= inputCharLen) && (unicode!=9))
    		{
    			img.src = "http://www.vicsjavascripts.org.uk/StdImages/Three.gif";
    
    		}
    
    
    	//gets unwanted keypresses out
    	if (
    		(unicode==38) || //arrow up
    		(unicode==40) || //arrow down
    		(unicode==37) || //arrow left
    		(unicode==39) || //arrow right
    		(unicode==13) || //enter
    		(unicode==27) || //escape
    		(unicode==46) || //delete
    		(unicode==16) || //shift
    		(unicode==17) || //ctrl
    		(unicode==18) || //alt
    		(unicode==93) || //
    		(unicode==91) || //
    		(unicode==20) || //
    		(unicode==223)
    		)
    		{
    			img.src = "http://www.vicsjavascripts.org.uk/StdImages/One.gif";
    		}
    
    
    
    }
    
    function Blur(img){
      var img=document.getElementById(img);
      img.src = "http://www.vicsjavascripts.org.uk/StdImages/Two.gif";
    
    }
    /*]]>*/
    </script></head>
    
    <body>
    <input name="" onblur="Blur('image1')" onkeyup=" gifOn(this,3,'image1');" /><img id="image1" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="50" height="50" />
    <input name="" onblur="Blur('image2')" onkeyup=" gifOn(this,3,'image2');" /><img id="image2" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="50" height="50" />
    
    </body>
    
    </html>
    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. #3
    Join Date
    Nov 2008
    Posts
    9
    Vic thank you for letting me learn a bit more today
    Happy New Year.

    Jeff

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles