Page 1 of 1

How to stop a anchor tag redirection ?

Posted: Thu Sep 17, 2009 8:09 am
by mukunthan
Hi,

I have a toplink
<a href="sow_lock.php" onclick="return chkBeforeLocking('S1')">Lock</a> on my page.

I want to stop it from going to the page(sow_lock.php) if AJAX response returns an error message. But it always goes to the page after displaying the error alert message.

function chkBeforeLocking(val){

if(val != ""){

var vresponse ;

http.open("GET", "chk_before_locking.php?sow_id="+val,true);


http.onreadystatechange = function(){

if(http.readyState == 4 ) { //&& http.status == 200

vresponse = http.responseText; alert(vresponse)


if(vresponse != "noerror"){

alert(vresponse);

return false;

}

}

}
http.send(null);


}
}

Kindly tell me why it does not stop if there is an error?

P.S : http is DOM object and the result of chk_before_locking.php page is either one of the following message
1.Pricesheet and Employee Roster are blank. Edit them before locking
2.Pricesheet is blank. Edit it before locking
3.Empsheet is blank. Edit it before locking
4.noerror

Re: How to stop a anchor tag redirection ?

Posted: Thu Sep 17, 2009 9:44 am
by jackpf
Hmm...I haven't actually read your code (I would if it were posted between

Code: Select all

 tags ;)) but you need to return false...that will always stop the browser performing it's default action for the event.