I'm currently developing a web application for scientific paper database management system, and am having issues with an AJAX function that is supposed to update multiple divs with the same name.
Schema background in simple terms is as follows:
There are multiple [papers] inside a [project] - call these [project_papers]. There are also 0 to many [subprojects] within the [project]. In the case of the screenshot example below there are 2 subprojects. A [project_paper] can exist in multiple [subprojects] within the project, or in none at all. Each row representing a [project_paper] on the screen has a "pin", which kind of acts like a sticky row when the contents of the project are contracted (hiding the ones with the pin off). The pin is a span with an id and name of "pPaper{project_paper_id}"
, which is normally fine.
However, and this is where the problem exists, if the [project_paper] exists in two [subprojects] simultaneously, the span will of course have the same id and name as there is no differentiation between subprojects. Personally, I think this should be correct, and any javascript designed to update the contents of the span should apply to all instances on the page, but it only updates the top one - the database side of the AJAX fires correctly, and therefore the [project_paper] has the pin flag changed, but the display ends up confusingly incorrect.
Is there any way to update the javascript to update the content of both spans?
Screenshot example (rows in yellow are the one with the same id -- pin is red thing on the left):
http://rdms.powerwatch.org.uk/rdms1.pngScreenshot example with changed pin (top row pin changed but not bottom row):
http://rdms.powerwatch.org.uk/rdms2.pngHTML that calls the javascript function:
----------
<span name="pPaper<%=CLng(RS("pr
oject_pape
r_id"))%>"
id="pPaper<%
=CLng(RS("project_paper_id
"))%>"><im
g src="/images/buttons/pin_<
%
=projPaperPin%>.gif" border="0" onClick="setProjectPin(<%
=CLng(RS("project_paper_id
"))%>,<%=t
heUID%>)" /></span>
-----------
Javascript functions:
-----------
/* Adjusts the pin status of a project paper within project or subproject for the active user */
var projPapPin;
function setProjectPin(projectPaper
ID,userID)
{
projPapPin = projectPaperID;
xmlHttp=GetXmlHttpObject()
;
url="/includes/ajax/ch_pro
jectpin.as
p?projPape
rID="+proj
ectPaperID
+"&userID=
"+userID+"
&sid="+Mat
h.random()
;
xmlHttp.onreadystatechange
=displayPr
ojectPin;
xmlHttp.open("GET",url,tru
e);
xmlHttp.send(null);
}
function displayProjectPin()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="compl
ete")
{
document.getElementById('p
Paper'+pro
jPapPin).i
nnerHTML = xmlHttp.responseText;
}
}
-----------