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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie AJAX and DIV question....

Status
Not open for further replies.

combs

Programmer
Apr 18, 2002
78
US
Hi,

I have a page that displays (in a table) information to the user reflecting what is IN the database and they may change the data by editing it as shown and then SAVE the data back to the database by clicking on a button.

As each field is updated (via AJAX calls), I would like a little green check mark to display next to the cell in the table. This is where the problem comes in....

If I run the code with an alert message showing me what the SQL is being sent to the database, it runs fine. All the green check marks show up. If I comment out the alert and just let the code run as intended, the only check mark to appear is the very last one -- which I assume is the last bit of code executed.

I've tried slowing down the code with a clever pause function that I found online, but that does not help. I know I'm (being a Newbie) probably missing the big picture here of how things are functioning, but how can I make the check marks show up as the code is executed??

Here is how the check marks are hidden on the page to begin with:
Code:
<div align="center"><span id="person" style="display:none"><img src="images/green_tick.png" width="20" height="19"></span></div>

Here is the code that is called upon the return in AJAX that should be showing the checkboxes:
Code:
function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
  if (xmlHttp.status != 200)
   {
    alert("file not found: " + xmlHttp.status);
	return;
   }
  else
   {
    var message = xmlHttp.responseText;
    if (!message)
    {
     //alert("invalid AJAX response or file!");
	 return;
    }
    else
	{
	 //alert("message is:  " + message);
     document.getElementById(message).style.display = 'block';
	 pausecomp(1250);
	}
  }
 }
}

Thanks for your time!
 
Okay,

I guess I didn't do a good job of explaining what I needed here....

Here's a link to the working code. The only check mark to appear is the last one.... I'd like a check mark to appear next to each row as the information is updated in the database.


I would welcome any comments or suggestions.

 
That is really more traffic than it needs to be. Not to mention a security risk.

Looking at that source I could craft some SQL and submit it to the proper URL to have it executed.

What you should really do is send the values back to the server using AJAX, and have DoEdit.asp create the SQL and VALIDATE the value and run it.

As for the more traffic part - you have a request going back to the server for each field. In order to save requests and therefore time - you could send all the values back in one call and have it updated.

If you really want to update one at a time I would consider putting the pause call in the for loop of the Update function rather than the callback function.
 
Borvik,

Thanks for your response. The script is in a very public place now, but will not be residing there for it's intended use. I realize the security risk at this location with the execution of SQL's and possible injection problems....

Ultimately, this will be running on a intranet where those kinds of security risks are minimal to non-existant.

I will try and implement your suggestion about the location of the pause call.

-DC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top