drde3456 2015-02-18 08:53
浏览 45

如何确保移动到java页面时php变量不会消失?

<?php

print "<td><a href=q.php?pcode=$pcode><img height=200 src=image/$pcode.jpg </a></td>";

?>

This is what I have written on my php page, once I click the image a prompt box will appear asking me for the quantity that I want the product, which is represented through the image.

<script type="text/javascript">

function typequantity () 
{
    q=prompt("Quantity?","");

    if (q!=0 && q!="" && q!=null )
    {   
        window.location.href = "http://localhost/buy.php?q="+q;
    }
    else 
    {
        window.location.href = "http://localhost/buy.php";
    }

}
</script>

<body onload="typequantity()">
</body>

However, the quantity does sends back, but the pcode is lost, and I need both of them.

  • 写回答

1条回答 默认 最新

  • douaoli5328 2015-02-18 09:59
    关注

    I agree that your question is not well formatted but i understood, check this out.

    <?php 
        echo '<a href="http://localhost/q.php?pcode='.$pcode.'" id="link" onclick="typequantity(this); return false;"><img src="image/pcode.jpg" height="200" /></a>';
    ?>
    
    <script type="text/javascript">
    function typequantity(obj)
    {
        //Get the arg from the link
        arg = obj.getAttribute("href").split("=");
    
        q = prompt("Quantity?","");
        if (q!=0 && q!="" && q!=null ){   
            window.location.href = "http://localhost/buy.php?q=" + q + "&pcode=" + arg[1];
        }
        else 
        {
            window.location.href = "http://localhost/buy.php";
        }
    }    
    </script>
    
    <body>
    </body>
    

    Next time be careful at your formatting.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统