From: shall on
When a user sets focus on a textbox, I want this AJAX dropdown to run
ONCE.
If the user goes BACK to that same textbox, I do NOT want the
"GetMyFile" to execute again.

How can I do this?

function show2Multi(aname,alist)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(alist).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","GetMyFile.asp?f="+allYears+"&a="+aname,true);
xmlhttp.send();
}

TIA
Steve
From: Captain Paralytic on
On 5 Aug, 16:13, sh...(a)uaex.edu wrote:
> When a user sets focus on a textbox, I want this AJAX dropdown to run
> ONCE.
> If the user goes BACK to that same textbox, I do NOT want the
> "GetMyFile" to execute again.
>
> How can I do this?
>
> function show2Multi(aname,alist)
> {
> if (window.XMLHttpRequest)
>   {// code for IE7+, Firefox, Chrome, Opera, Safari
>   xmlhttp=new XMLHttpRequest();
>   }
> else
>   {// code for IE6, IE5
>   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
>   }
> xmlhttp.onreadystatechange=function()
>   {
>   if (xmlhttp.readyState==4 && xmlhttp.status==200)
>     {
>     document.getElementById(alist).innerHTML=xmlhttp.responseText;
>     }
>   }
> xmlhttp.open("GET","GetMyFile.asp?f="+allYears+"&a="+aname,true);
> xmlhttp.send();
>
> }
>
> TIA
> Steve

Remove the event trigger from the box once it loses focus.
From: Denis McMahon on
On 05/08/10 16:13, shall(a)uaex.edu wrote:
> When a user sets focus on a textbox, I want this AJAX dropdown to run
> ONCE.
> If the user goes BACK to that same textbox, I do NOT want the
> "GetMyFile" to execute again.
>
> How can I do this?

I'm not sure if by "textbox" you mean

(a) textarea; or
(b) input type="text"

element.

You could change the onFocus property of the element during the call to
GetMyFile.

eg, *IF* aname is the id of the "textbox" element:

function GetMyFile(aname,alist)
{
tbox = document.getElementById(aname);
tbox.onFocus = "";

..... rest of function

}

or, if aname is not the name of the textbox, change the onFocus handler
like this:

onfocus="GetMyFile('aname','alist',this)"

Then:

function GetMyFile(aname,alist,caller)
{
caller.onFocus = "";

..... rest of function

}

You may wish to add some logic to prevent the onFocus removal from
elements of other types, or limit it to specific elements.

Other methods include:

Setting a global variable, eg:

var gmfDoneOnce = false;

function GetMyFile(aname,alist)
{

if (gmfDoneOnce) return;
gmfDoneOnce = true;

..... rest of function

}

but that will mean that the function can only run once, regardles of how
many different places you may wish to call it from.

Rgds

Denis McMahon
From: Richard Cornford on
On Aug 5, 4:43 pm, Denis McMahon wrote:
<snip>
> eg, *IF* aname is the id of the "textbox" element:
>
> function GetMyFile(aname,alist)
> {
> tbox = document.getElementById(aname);
> tbox.onFocus = "";
>
<snip>

If the intention is to remove an - onfocus - intrinsic event listener
function from a DOM element that it would be better if the identifier
were spelled with all lowercase letters, and the value assigned be
null (as some browsers (at lest IE) don't like anything but null or a
function to be assigned to such properties).

Richard.