Jump to content

Javascript not calling function...


RIRedinPA

Recommended Posts

I have this ongoing project that is a tracking site for the publication of our magazines. It's essentially a grid with each article/feature in an issue of the magazine on the Y access and the required checks/steps on the X...you can toggle between two views, art and editorial...the grid is basically created by a bunch of unordered lists made pretty by CSS...each <li> tag contains either a textarea or checkbox depending on need. Users update the record by one of two ways, either typing directly into the textareas or a pop up window. You pick your preference through radio buttons located at the top of the screen. (See first attached image).

 

I have a bunch of little javascript functions utilizing AJAX to control everything...ad new rows, delete rows, change groups for items, etc. The main function is one called showtable() which queries the database for the issue you are viewing and then displays the data...this is called when the site loads and whenever you do something that would change the data...for example...adding a row the process goes like this:

 

click add row button-->fire up javascript-->pass values to PHP file through AJAX-->add new row-->echo back to JS Func-->call showtable function to display changes

 

works fine for everything else...

 

except for updating data...if I am updating inline (from a textarea) it works fine, I use an onchange handler to call the update function, pass the new values through AJAX to PHP, update database, pass back a everything worked fine confirmation, call showtable, change is displayed...(see 2nd attachment, I grayed out a textarea, not that that is that useful but what the hey)...

 

if I am updating from the window/dialog box not so good...this process works onmousedown, displays window, which has a textarea and a submit button with a onmousedown handler (see attachment 3, this fires the update function and everything works up to the showtable function, the new value is added to the db and I get into the showtable function but it doesn't go through the whole process, it dies mid function...basically you have to refresh the page manually to see the changes...I've been on this for two days and I am at a loss as to why it won't work...

 

Here are 4 relevant javascript functions, the showtable function, showupdate (which displays the update window), updaterecord and addrow (to show how that I am calling showtables() the same from other functions as I am in updaterecord...)...I also added my clearmsg function which just clears out a message box

 


//use this function to reload the table
function showtable(view, where) { 

			if (view == "") {
				view = "edit"; 
			}

//-->it keeps dying here
			var radiolength = document.forms[0].updateoption.length;


			//get update option
			for(op=0; op<radiolength; op++) {
				if (document.forms[0].updateoption[op].checked == true) { 
					var updateloc = document.forms[0].updateoption[op].value;
				}
			}

			xmlHttp = checkajax();

			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					//alert(xmlHttp.responseText);
					var returneditems = xmlHttp.responseText.split("::");
					document.getElementById("header").innerHTML = returneditems[0];
					document.getElementById("content").innerHTML = returneditems[1];
					document.getElementById("toolbox").innerHTML = returneditems[2];
				}	
			}
			xmlHttp.open("GET", "lib/maketable.php?view=" + view + "&updateloc=" + updateloc, true);
			xmlHttp.send(null);

		}


function showupdate(objid, itemid, thisfield, updateloc) {

			var xmlHttp = checkajax();
			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					//alert(xmlHttp.responseText);
					document.getElementById('update').innerHTML = xmlHttp.responseText
					document.getElementById('update').style.display = "block";
					docuemnt.updateform.comments.focus();

				}
			}

			xmlHttp.open("GET", "lib/showupdate.php?objid=" + objid + "&itemid=" + itemid + "&thisfield=" + thisfield + "&updateloc=" + updateloc, true);
			xmlHttp.send(null);
		}

function updaterecord(objid, itemid, value, thisfield, updateloc) {

			if (updateloc == "window") { 
				//get value
				var theform = document.updateform;
				value = theform.comments.value;
			}

			var xmlHttp = checkajax();
			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					//alert(xmlHttp.responseText);
					var returneditems = xmlHttp.responseText.split("::");
					var msg = returneditems[0];
					var view = returneditems[1];

					document.getElementById('update').style.display = "none";
					document.getElementById('msgbox').innerHTML = msg;
					document.getElementById('msgbox').style.display = "block";

					alert("ok");

					colorFade('msgbox','background','ffffff','CCFF66');

					if (updateloc == "window") { 
						document.getElementById('update').style.display = "none";
					}

				}
			}

			xmlHttp.open("GET", "lib/updatedb.php?itemid=" + itemid + "&value=" + value + "&thisfield=" + thisfield, true);
			xmlHttp.send(null);

		}

function addrow(thisissue) { 

			clearmsgbox('CCFF66');

			var xmlHttp = checkajax();

			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					var returneditems = xmlHttp.responseText.split("::");
					var msg = returneditems[0];
					var view = returneditems[1];
					document.getElementById('msgbox').innerHTML = msg;
					document.getElementById('msgbox').style.display = "block";
					colorFade('msgbox','background','ffffff','CCFF66');
					showtable(view, 'addrow');
				}
			}

			xmlHttp.open("GET", "lib/addrow.php?thisid=thisissue=" + thisissue, true);
			xmlHttp.send(null);

			setTimeout ('clearmsgbox(\'CCFF66\')', 10000);
		}
function clearmsgbox(thecolor) {
			if (thecolor == "CCFF66" || thecolor == "") { 
				document.getElementById('msgbox').innerHTML = "";
				colorFade('msgbox','background','CCFF66','FFFFFF');
			} else if (thecolor == "FF0066") {
				document.getElementById('msgbox').innerHTML = "";
				colorFade('msgbox','background','FF0066','FFFFFF');
			}
		}


 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.