/    Sign up×
Community /Pin to ProfileBookmark

Javascript class modification

I’m creating an active ajax interface where on one side the user will select the category and then on the other side that categories contents will show. Currently I have it set so the categories bkg color changes on hover and once it is selected via javascript in the ajax script below. My question is that once it is selected it stays selected; how do I have one of the categories clear it’s class when another category is selected. Script and example image are below

[CODE]function populatestudents(class)
{
var urlstd = “/phpscripts/rsrch_students.php?param=”;
http.open(“GET”, urlstd + escape(class), true);
document.getElementById(class).setAttribute(“class”, “active”);
document.getElementById(“studentresult”).innerHTML=”<img src=’/images/ajax-loader.gif’ style=’margin:50px 0 0 150px;’/>”;
http.onreadystatechange = handleHttpResponseStdLdSTU;
http.send(null);
}

function handleHttpResponseStdLdSTU()
{
if (http.readyState == 4)
{
resultsuserSTU = http.responseText;
/* On php script completion print script result in response div */
if(resultsuserSTU == “”) resultsuserSTU = “”;
document.getElementById(‘studentresult’).innerHTML = resultsuserSTU;
// evaluate javascript
scriptTag='(<script.*?>)((n|r|.)*?)(</script>)’;
if (scripts=resultsuserSTU.match(scriptTag)) {
// remove slashes
scripts[2]=scripts[2].replace(/\/g,””);
//run scripts
eval(scripts[2]);
}
}
}

function getHTTPObjectStdLdSTU()
{
var xmlhttpSTU;
if (!xmlhttpSTU && typeof XMLHttpRequest != ‘undefined’)
{
try {xmlhttpSTU = new XMLHttpRequest();} catch (e) {xmlhttpSTU = false;}
}

//KILL HERE
//END KILL
return xmlhttpSTU;
}
var http = getHTTPObjectStdLdSTU();[/CODE]

example image:[url]http://fitness.recorded-live.com/images/ex.jpg[/url]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorDec 07.2008 — if you are asking how to clear/empty the content area then probably
<i>
</i>document.getElementById("studentresult").innerHTML= '';


If you are asking anything else, you didn't provide enough code.
Copy linkTweet thisAlerts:
@rnd_meDec 08.2008 — [CODE]function populatestudents(class)
{

var urlstd = "/phpscripts/rsrch_students.php?param=";
http.open("GET", urlstd + escape(class), true);
document.getElementById(class).setAttribute("class", "active");

[COLOR="SeaGreen"]if(populatestudents.old){

document.getElementById(populatestudents.old).setAttribute("class", "");
}
populatestudents.old=class;
[/COLOR]
document.getElementById("studentresult").innerHTML="<img src='/images/ajax-loader.gif' style='margin:50px 0 0 150px;'/>";
http.onreadystatechange = handleHttpResponseStdLdSTU;
http.send(null);
}[/CODE]
×

Success!

Help @cfgcjm 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.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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