/    Sign up×
Community /Pin to ProfileBookmark

Function Only Runs Once

I am trying to call an AJAX function to display a block of text in a div every time the button is pressed. The problem is that the function will only run once – if the user clicks to cancel from inside the box, the display function wont run again.

Here are the two functions:

function block(field){
var ajaxRequest; // The variable that makes Ajax possible!
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try{
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e){
alert(“Your browser broke!”);
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById(field).innerHTML = ajaxRequest.responseText;
}
}
block=”block.php?block=”+field;
ajaxRequest.open(“GET”, block, true);
ajaxRequest.send(null);
}

function blank(field) {
document.getElementById(field).innerHTML = “”;
}

Any help would be greatly appreciated. Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyJan 01.2009 — I'd run it through an interactive script debugger to see what it is doing. I use both IE with MS Script Debugger and Firefox with Firebug Script Debugger.
×

Success!

Help @t_cohen_6_gmail 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.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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