/    Sign up×
Community /Pin to ProfileBookmark

Passing id parameter in ajax

I am trying to pass an element’s id to an ajax function so that I can update different areas by passing different ids to the same function, but I am not quite sure how to get it passed to where I want it to go.

[code]
function calGet(date,month,year,id,action) {
xmlHttp=GetXmlHttpObject();

if(xmlHttp==null) {//ajax won’t work, redirect to a calendar php page to display the event with php
window.location = “localhost/panl/eventCalendar.php?date=”+date+”&month=”+month+”&year=”+year;
return;
}

var url = “http://localhost/panl/scripts/calendar.php”;
url=url+”?date=”+date+”&month=”+month+”&year=”+year+”&run=”+action;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);

}

function stateChanged() {
if(xmlHttp.readyState==4) {
document.getElementById(‘calEvent’).innerHTML=xmlHttp.responseText;
}
}
[/code]

In the function calGet I passed a parameter ‘id’. I want to get this parameter down into the getElementById area in the stateChanged function and I’ve tried, many many ways, but I cannot figure it out.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMar 02.2007 — Make it a global variable:
var myid = null;

function calGet(date,month,year,id,action) {
xmlHttp=GetXmlHttpObject();
myid = id;
if(xmlHttp==null) {//ajax won't work, redirect to a calendar php page to display the event with php
window.location = "localhost/panl/eventCalendar.php?date="+date+"&month="+month+"&year="+year;
return;
}

var url = "http://localhost/panl/scripts/calendar.php";
url=url+"?date="+date+"&month="+month+"&year="+year+"&run="+action;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

function stateChanged() {
if(xmlHttp.readyState==4) {
document.getElementById(myid).innerHTML=xmlHttp.responseText;
}
}
Copy linkTweet thisAlerts:
@aj_nscauthorMar 02.2007 — works perfect. thanks.
Copy linkTweet thisAlerts:
@konithomimoMar 02.2007 — No porblem.
Copy linkTweet thisAlerts:
@Arumugam_SFeb 12.2010 — If the parameter has symbols like +,#, how could be passed in url? The url will encoded the symbols know, what is the alternative solution for this issue,

Any suggestion would be appreciated

Thanks
×

Success!

Help @aj_nsc 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 5.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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