Hi guys i am new to this forum facing some issues with my php code.
The code below says on click go to cart.php
I want to add a condition to the same--

if(reasons==Internal)
{
go to="cart1.php"
}
else
{
go to="cart.php"
}

Kindly help me with the same....

<td>
     <p align="center">
          <input name="Next" type="button" id="Next" value="Next" onmouseover="reasonempty();"onclick='javascript:window.location.href="cart.php?form=tmrfForm&field="+document.getElementById("reasons").value+"&field5="+document.getElementById("weekend").value,"","top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes"; return false;'>
                  </p>
                  </td>

Recommended Answers

All 6 Replies

Member Avatar for diafol

Use [ CODE ] tags

if($reasons=='Internal'){
  header("Location: cart1.php");
}else{
  header("Location: cart.php");
}
exit;

Thanks ardav,
But it will be appreciable if you can tell me where to put the code i mean before on click or after onclick stmt

Hey dipusubhasis,

The php-code given by ardav is the same that I wanted to give it to you.
Please tell what exactly you want. the info. given by you is insufficient.

I mean the variable '$reason' from where will we get its information.

try this if this solves your problem. if not you need to tell the whole thing.

<?php
// The php Code to Select the page.
$page = "";
if($reasons=='Internal'){
  $page = "cart1.php";
}else{
  $page = "cart.php";
}

?>

<!-- Your HTML FORM -->
<td>
<p align="center">
<input name="Next" type="button" id="Next" value="Next" onmouseover="reasonempty();"onclick='javascript:window.location.href="<?php echo $page; ?>?form=tmrfForm&field="+document.getElementById("reasons").value+"&field5="+document.getElementById("weekend").value,"","top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes"; return false;'>
</p>
</td>

Please Check if this works or not.

I think you need javascript. If I'm correct, try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
        <script type="text/javascript">
            function goto()
            {
                if(reasons=="Internal")
                {
                    window.location.href="cart1.php?form=tmrfForm&field="+document.getElementById("reasons").value+"&field5="+document.getElementById("weekend").value,"","top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes"; 
                    return false;
                }
                else
                {
                    window.location.href="cart.php?form=tmrfForm&field="+document.getElementById("reasons").value+"&field5="+document.getElementById("weekend").value,"","top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes"; 
                    return false;
                }
            }
        </script>
    </head>
    
    <body>
    <!-- ......
    ......
    ...... -->
    <td>
    <p align="center">
    <input name="Next" type="button" id="Next" value="Next" onmouseover="reasonempty();" onclick='goto()'>
    </p>
    </td>
     <!-- ......
    ......
    ...... -->
    </body>
</html>

changing locations, not opening a window

"","top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes";

is bull

commented: yes +6

then the script may be like this

function goto()
{
if(reasons=="Internal")
{
window.open("cart1.php?form=tmrfForm&field="+document.getElementById('reasons').value+"&field5="+document.getElementById('weekend').value+",'','top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes'");
return false;
}
else
{
window.open("cart.php?form=tmrfForm&field="+document.getElementById('reasons').value+"&field5="+document.getElementById('weekend').value+",'','top=0,left=400,width=1000,height=1000,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,status=yes'");
return false;
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.