Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line of code won't execute - Wierd!

Status
Not open for further replies.

zinja

MIS
Nov 14, 2002
149
US
Anyone have an idea as to why this first line of this function doesn't execute until after the ajax request is sent?

Code:
function readcheck(paymentamount)
{
	printchange("Insert Check into Scanner");
	for (var i=0; i<=3; i++)
	{
		//alert("Ready to Insert Check?");
		if (!workspace[ws_index].gotnewtransid)
		{
			getnewtransid();
		}
		if (workspace[ws_index].newtransid)
		{
			workspace[ws_index].gotnewtransid = true;
		}
		var request = 'type=chk&txnid=' + workspace[ws_index].newtransid + 
			'&amt=' + paymentamount + '&host=' + checkreader;
		ajaxrequest.open("POST", micr_url + request, false);
		ajaxrequest.send(null);
		var response = ajaxrequest.responseXML.documentElement;
		//var resp = eval(httpResponse(micr_url,'POST',request));
		try
		{
			var scanstatus = response.getElementsByTagName('MicrStatus')[0].firstChild.nodeValue;
			if (scanstatus == 'OK')
			{
				var chknum = response.getElementsByTagName('MicrSerial')[0].firstChild.nodeValue;
				workspace[ws_index].checknumber = chknum;
				//printchange("Success! <br># " + chknum );
				return(true);
			}
			else
			{
				printchange("Check not read - Reinsert");
				//alert("Check not read - Reinsert");
			}
		}
		catch(err)
		{
			printchange("Check not read - Reinsert");
			//alert("Check not read - Reinsert");
		}
	}
	return(false);
}

I am at a loss as to why it doesn't execute properly. If I put an alert() in there below the
Code:
printchange("Insert Check into Scanner");
line, it will execute. Very wierd.

Thanks,

LJ

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Way above this function. Does it matter?

Thanks for responding and please let me know if that matters and why (I am fairly new to javascript).

Thanks,

LJ

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
I tried moving the printchange function down below the readcheck function, but still not working properly.

Thanks!

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
From my understanding javascript executes top to bottom unless there is a function call in which case control is given to the function, that also executes top to bottom, then it continues executing where it left off.
if your code is structured
Code:
function somefunction(){
	someOtherFunction() <---- error here or not working properly;
}
my instinct would be to look at the function that is failing which is why I asked to see where princhanged was defined or what it does.
 
Is there some reason you're avoiding showing us the printchange() function?

Lee
 
No reason. Here ya go:
Code:
// @printchange
function printchange(text, total) 
{
	if (total)
	{
		document.getElementById('RxSign').innerHTML = '<div style="' + cssMsg + '">' + '<br>' + text + "<br>" + total + '</div>' ;
	}
	else
	{
		document.getElementById('RxSign').innerHTML = '<div style="' + cssMsg + '">' + '<br>' + text  + '</div>' ;
	}
}

I thought it worked the same as other languages and control would be passed to the called function until it finished and then code execution would begin where it left off (the calling function).

Let me know your thoughts.

I can put an alert(" "); in there right below the printchange call and it works. If not, no worky.

Thanks again!


LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top