/    Sign up×
Community /Pin to ProfileBookmark

AJAX program not working help!!

I have a problem with an AJAX program I am coding. What it does is the user logs in then there is a select box that pulls data from an XML file. The user can select a value from the list that sends a request to pull info from the XML file and adds it to a table below the select list.

I am having problems after the user selects an item and the getAcctInfo function. Can some one help me with this?

[CODE]

<html>
<head>

<style>
#AcctInfo {
position: absolute;
left: 20px;
top: 150px;
height: 400px;
width: 1024px;
font-family: Arial, Helvetica, sans-serif;
}
</style>

<title></title>

<script>

var obj; /////Target Div////
var objAcctInfo;
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
XMLHttpRequestObject.overrideMimeType(“text/xml”); //XML
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject(“Microsoft.XMLHTTP”);
}

////////Logon function////////
function validateLogon(dataSource, divID)
{
var aUser = document.getElementById(‘userid’).value;
var aPassword = document.getElementById(‘password’).value;

var data = aUser + ‘|’ + aPassword; //This create a delimited string

getXML(dataSource, divID, data);

return false;
}

function getAcctInfo(dataSource)
{
alert(“dataSource-getAcctInfo:” + dataSource);
alert(“Inside the getAcctInfo function:”);
var myAcctSelected = document.getElementById(“myaccts”).value;
alert(“myAcctSelected-getAcctInfo:” + myAcctSelected);
//displayXML(myAcctSelected);
getXML(myAcctSelected);
// return false;
}

////////Get XML data////////
function getXML(dataSource, divID, data, myAcctSelected, myLogonText)
{
alert(“myAcctSelected-getXML:” + myAcctSelected);
alert(dataSource + ” ” + divID + ” ” + data);

if(XMLHttpRequestObject)
{
obj = document.getElementById(divID);

XMLHttpRequestObject.open(“POST”, dataSource);
XMLHttpRequestObject.setRequestHeader(‘Content-Type’,
‘application/x-www-form-urlencoded’);

XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
//eval(XMLHttpRequestObject.responseXML); //XML
var myXML = XMLHttpRequestObject.responseXML; //XML
displayXML(myXML, myAcctSelected, myLogonText);
}
}
XMLHttpRequestObject.send(“data=” + data);
}
}

////////display XML data///////
function displayXML(myXML)
{
alert(“Inside the displayXML”);
//program quits
alert(“XML: ” + myXML);

var XMLElements = myXML.getElementsByTagName(“logon”);
var myLogonText = XMLElements[0].firstChild.data;
//alert(‘XMLElements:’ + XMLElements);
//alert(“myLogonText: ” + myLogonText);

////Checks XML file///
if (myLogonText == “Error”)
{
//alert(“error”);
obj.innerHTML = “<br><font color =red> Error: User Id is not valid, please try again. </br></br> </font>”;
} else {

if (myLogonText == “Trans”)
{
alert(“myLogonText ==’Trans'”);
displayTrans(myXML);
return;
}

var CategoryElements = myXML.getElementsByTagName(“category”);

var myHTML = “<h2>Finances</h2>”;
var myHTML = myHTML + “Select Category:”;
var myHTML = myHTML + “<br>&nbsp;&nbsp;&nbsp;<select id=”myaccts” onChange=”getAcctInfo(‘displayTrans.php’, ‘AcctInfo’);”>n”;
myHTML = myHTML + “<option value='” + “-” + “‘>” + “-” + “</option>/n”;

for (loopIndex = 0; loopIndex < CategoryElements.length; loopIndex++)
{
var myData = CategoryElements[loopIndex].firstChild.data;
myHTML = myHTML + “<option value='” + myData + “‘>” + myData + “</option>/n”
}

var myHTML = myHTML + “</select>/n”;

///hides logon form////
var myLogonForm = document.getElementById(“LogonForm”);
myLogonForm.style.visibility = “hidden”;

var myTargetDiv = document.getElementById(“targetDiv”);
myLogonForm.style.position = “absolute”;
myLogonForm.style.top = “10px”;
///hides logon form-END////

obj.innerHTML = myHTML;
}
}

function displayTrans(myXML, getXML)
{
alert(“Inside the displayTrans function”);
var myCategoryElements = document.getElementsByTagName(“trans”);

alert(“myCategoryElements: ” + myCategoryElements);
//alert(“Inside the if XMLTableElements”);

var myHTML = “n<hr><table border=1>n”;
var myHTML = myHTML + “<tr><th>” + “Item” + “</th></tr>”;

for (loopIndex = 0; loopIndex < myCategoryElements.length; loopIndex++)
{
var myTableData = myCategoryElements[loopIndex].firstChild.data;
myHTML = myHTML + “<tr><th>” + myCategoryElements[loopIndex].firstChild.data + “</th></tr>”;
}

myHTML = myHTML + “</table>n”;

var objAcctInfo = document.getElementById(“AcctInfo”);
objAcctInfo.innerHTML = myHTML;
}

</script>
</head>

<body bgcolor=”#C0C0C0″>
<div id=LogonForm>

<H2>Logon</H2>

<form name=myform id=myform>
<table>

<tr>
<td>Userid:</td>
<td><input name=’userid’ id=’userid’ type=’text’ size=’10’></td>
</tr>
<tr>
<td>Password:</td>
<td><input name=’password’ id=’password’ type=’password’ size=’10’> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td><br><input type=submit value=”Logon” onClick=”return validateLogon(‘validate_logonxml_accounts.php’, ‘targetDiv’)”></td>
</tr>
</table>

</form>

</div>

<div id=targetDiv>

</div>

<div id=selectDiv>

</select>

</div>

<div name=AcctInfo id=AcctInfo>
</div>

</body>
</html>

[/CODE]

Thanks ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@wb31authorFeb 24.2010 — Anyone??? ?
Copy linkTweet thisAlerts:
@kubasFeb 24.2010 — But what's the problem exactly, where it stucs ?

maybe put it on internet so everyone can test by themselves.
Copy linkTweet thisAlerts:
@wb31authorFeb 25.2010 — The program is not showing the table with the information. It work fine up until the user selects data from the select list. It needs to display a different table for each choice the user selects. So, if the user selects option A or option B it should call the getAcctInfo function. What the user selects is getting lost in the getXML function. The getXML function calls a request to the server. Then should check the displayXML function, if (myLogonText == "Trans"), this should call displayTrans function and put the XML data into the table.

I am not able to put the program online. Let me know if anything is not clear in the paragraph above.

Thanks for the help
×

Success!

Help @wb31 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...