/    Sign up×
Community /Pin to ProfileBookmark

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”;
}

}

[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsDec 31.2008 — [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>[/CODE]
Copy linkTweet thisAlerts:
@jeff7691authorDec 31.2008 — Vic thank you for letting me learn a bit more today ?

Happy New Year.

Jeff
×

Success!

Help @jeff7691 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...