Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP -> Javascript -> PHP : 2 values for one variable!?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP -> Javascript -> PHP : 2 values for one variable!?

Postby qeylIS » Thu Apr 03, 2003 3:48 am

Hi, I made a PHP function, using Javascript. This calls a confirm message (ok/cancel). It returns the values "ok" or "cancel"

Code: Select all
function alertokcancel($text,&$res)
{
echo "<script> var text = '$text'; </script>";
?>
<script language="JavaScript">
if (window.confirm(text)) {
res="ok";
} else {
res="cancel";
}
</script>
<?
$res = "<script language=\"JavaScript\"> document.write(res);</script>";
}

If i echo the result it is either "ok" or "cancel", but in an if-statement the value of the variable is always equal to 0!
Call:

Code: Select all
alertokcancel($lang['nonactive'],&$res);

echo $res //is "ok" or "cancel"
if ($res=="ok")
{
//will only go to this part if: IF($res==0) is the statement
}


How is this possible, and how can i modify my if-statement so that it does check the values "ok" or "cancel"; (in other words how can I put the value of
Code: Select all
echo $res
in a variable?

Please advice,

Marijn
qeylIS
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Apr 03, 2003 3:41 am

Postby Redcircle » Thu Apr 03, 2003 4:30 pm

because php is on the server side and javascrpt is on the client side you would need to post it to the server with a form or through the url.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby qeylIS » Thu Apr 03, 2003 10:47 pm

I thought it might be that, but what i find strange is that when I echo $res it shows the assigned value. So there must be a way somehow to get that information???
qeylIS
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Apr 03, 2003 3:41 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron