Forum Moderators: coopster
echo "<script >var cnfrm=confirm('Are you sure to enter blank codes for Case:$case_id Subcase:$subcase_id?'); ";
echo"if(!cnfrm){ 'update_blankvlaues() '}</script>";
function update_blankvlaues()
{
echo("TEST");
}
The javascript:
function getHTTPObject() {
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
req = new ActiveXObject("Microsoft.XMLHTTP");
}
return req;
}
function update_blankvalues(sendpage, params){
if(http.readyState == 4 ¦¦ http.readyState == 0){
http.open("GET", sendpage + params, true);
http.onreadystatechange = handleGet;
http.send(null);
}
}
//deals with the servers' reply to requesting new content
function handleGet(){
if(http.readyState == 4){
if(http.status == 200){
alert(http.responseText);
}
}
}
var http = getHTTPObject();
The code to call the function:
echo "<script >var cnfrm=confirm('Are you sure to enter blank codes for Case:$case_id Subcase:$subcase_id?'); ";
echo"if(!cnfrm){ 'update_blankvalues('mypage.php','?somevariable=$somevalue') '}</script>";
Then, in mypage.php:
$somevariable = $_GET['somevariable'];
do some stuff with this value (insert into db, etc)
echo "test";
That's about the simplest example I can think of of an XMLHttprequest ....
But i felt its too complicated for me as i am a rookie- However i have something here can any one let me know what am i doing wrong here- I am trying to stop the execution of the function when if condition is executed(that is page is redirected to userview.php). Indeed it is redirecting when clicked cancel but as well executing the rest of the php code as well. How am i going to stop the execution of the php code in the function?
function update_blankvlaues($comments,$curr_mod_date,$curr_FY,$curr_halfyear,$curr_quarter,$curr_week_no,$case_id,$subcase_id
)
{
echo"<script>var cnfrm=confirm('Blank Code values for the Case:$case_id Subcase:$subcase_id');";
echo"if(!cnfrm)";
//echo"<!--\n";
echo"window.location = 'userview.php'\n;";
//echo"//-->}";
echo"</script>";
//Define connection settings
if(!$conn){
include('config.inc.php');
$conn=@mysql_connect( "localhost", "$qaft_db" ,"$qaft_pass" ) or die ("Err:Conn");
$rs= @mysql_select_db ("$qaft_db", $conn) or die ("Err:Db");
}