Forum Moderators: coopster

Message Too Old, No Replies

what is wrong with the code

         

ahmedwaseem2000

4:13 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



Can any one tell me why is this function call not working(this function is a php function)

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");

}

sned

4:25 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



PHP is a server-side language, meaning all the code gets read before it is even sent out, while the script is client side ... so while PHP can create scripts, these scripts can't call php functions, unless you use something like xmlhttprequest.

-sned

ahmedwaseem2000

4:26 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



an example would be of a great help!

sned

4:35 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



Ok, here's something I use to do some goofy session stuff (changed to use your function name):

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 ....

ahmedwaseem2000

9:23 am on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi - Thanks SNED.

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");
}