简体   繁体   English

javascript使用onclick函数定向返回页面

[英]javascript directing to back to the page using onclick function

I am trying to direct back to a page "jerseyCollection" if there is no value on price of total shop. 如果总店面价格没有价值,我将尝试返回到“ jerseyCollection”页面。 Here is the code. 这是代码。 I am including all the code because I think there is something crashing with onclick="checkOrder()" function which contains code to redirect user back to order page. 我包含所有代码,因为我认为onclick =“ checkOrder()”函数会崩溃,该函数包含将用户重定向到订单页面的代码。 Here is the code for function. 这是功能代码。 I know checkOrder() works because I have tried it with alert and i know redirecting statement works because I have tried it in other pages, too. 我知道checkOrder()起作用是因为我已经尝试过使用alert,并且我知道重定向语句也起作用了,因为我也在其他页面中尝试过。 But I just can't figure it out why it is not directing back to the shopping page even with no value in total shopping value.. Please help me figure this out. 但是我无法弄清楚为什么即使总购物价值没有价值,它也不能直接返回购物页面。.请帮助我解决这个问题。 and how to solve this. 以及如何解决这个问题。

function checkOrder(){
var x = document.choice.realTotal.value 
    if (x == false){
        alert ("Please do the shopping");
        window.location.href='jerseyCollection.php';
    }
}

<

    !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>Jersey Collection</title>
        <link href="general.css" type="text/css" rel="stylesheet" />
        <style type="text/css">
            table {
                    border: 4px solid #333333; 
                    width: 80%;    
                    margin-left: auto;
                    margin-right: auto; }
            td {
                    padding: 8px;
                    border 1px solid #333333;
                    background-color: #ccc; 
                    text-align: center; }
        </style>
        <script type="text/javascript" src="general.js" />
        </script>
    </head>
<body>
       <div>
        <div id="sidebar">
                <div style="color:#CCC">
                    <h2><a href="index.html">James' NBA Jersey Shop</a></h2>
                </div>
                <div>
                <FORM>
                    <p><INPUT Type="BUTTON" VALUE="Personal Info" ONCLICK="window.location.href='personalInfo.php'" /></p> 
                    <p><INPUT Type="BUTTON" VALUE="Jersey Collection" ONCLICK="window.location.href='jerseyCollection.php'" disabled /></p>
                    <p><INPUT Type="BUTTON" VALUE="Confirmation" ONCLICK="window.location.href='confirmation.php'" disabled /></p>
                    <p><INPUT Type="BUTTON" VALUE="Order" ONCLICK="window.location.href='order.html'" /></p>
                    <br>
                    <p><INPUT Type="reset" VALUE="Reset Order Info" /></p>
                    <br>
                    <br>
                    <p>Web Style Option</p>
                    <p><input name ="stylish" value="DGH" onclick="styleChange('DGH')" type="radio" checked="true" />Dark Gray & Gray & Helvetica</p> 
                    <p><input name ="stylish" value="RON" onclick="styleChange('RON')" type="radio" />Red & Orange & New York</p>  
                    <p><input name ="stylish" value="SBC" onclick="styleChange('SBC')" type="radio" />Sky Blue & Blue & Comic Sans</p> 

                </FORM>
                </div>
            </div>
    <div id="contents">
        <div>
            <h1 class="title">Jersey Collection</h1>      
        </div>
        <form name="choice" action="http://i6.cims.nyu.edu/~jwj243/Assignment5/confirmation.php" method="post">
        <table align="center">
            <tr>
                <td><img src="atlanta_josh_smith.jpg" width="200" height="200"/></td>
                <td><img src="boston_paul_pierce.jpg" width="200" height="200"/></td>
                <td><img src="brooklyn_deron_williams.jpg" width="200" height="200"/></td>
                <td><img src="chicago_derrick_rose.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $20<br>Quantity<input name="PROD_ajs_20" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value= 
                <?php if(isset($_COOKIE['name'])) echo $PROD_ajs_20; else echo 0;  ?> ></td>
                <td>Price: $25<br>Quantity<input name="PROD_bpp_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_bpp_25; else echo 0;  ?> ></td>
                <td>Price: $25<br>Quantity<input name="PROD_bdw_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_bdw_25; else echo 0; ?> ></td>
                <td>Price: $30<br>Quantity<input name="PROD_cdr_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_cdr_30; else echo 0; ?> ></td>
            </tr>
            <tr>
                <td><img src="houston_jeremy_lin.jpg" width="200" height="200"/></td>
                <td><img src="la_blake_griffin.jpg" width="200" height="200"/></td>
                <td><img src="la_kobe_bryant.jpg" width="200" height="200"/></td>
                <td><img src="miami_dwyane_wade.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $25<br>Quantity<input name="PROD_hjl_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_hjl_25; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_lbg_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_lbg_30; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_lkb_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_lkb_30; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_mdw_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_mdw_30; else echo 0; ?>  ></td>
            </tr>
            <tr>
                <td><img src="miami_lebron_james.jpg" width="200" height="200"/></td>
                <td><img src="ny_carmelo_anthony.jpg" width="200" height="200"/></td>
                <td><img src="okc_kevin_durant.jpg" width="200" height="200"/></td>
                <td><img src="orlando_dwight_howard.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $35<br>Quantity<input name="PROD_mlj_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_mlj_35; else echo 0; ?>  ></td>
                <td>Price: $35<br>Quantity<input name="PROD_nca_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_nca_35; else echo 0; ?>  ></td>
                <td>Price: $35<br>Quantity<input name="PROD_okd_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_okd_35; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_odh_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_odh_30; else echo 0; ?>  ></td>

            </tr>            

        </table>
        <div>
            <table>
                <tr>
                    <td>Total: <input type="text" id ="realTotal" name="realTotal" size=2 value = <?php if(isset($_COOKIE['name'])) echo $realTotal; ?> ></td>
                    <td><span name="order_total" id="order_total" style="text-align: right; font-size: 20px">$0.00</span></td>
                </tr>
                <tr>
                    <td><input type= "submit" value="Next" onclick="checkOrder()" ><input type="hidden" name="submitted" value ="true" /></td>
                    <td></td>
                </tr>
            </table>
        </div>
        </form>
     <br/><br/><br/><br/><br/><br/><br/>   
    </div>
</div>
</body>
</html>

Try this: 尝试这个:

function checkOrder(){
    var x = document.choice.realTotal.value;
    if (x == false){
        alert ("Please do the shopping");
        window.location.href='jerseyCollection.php';
        return false;
    }
}

In your code, the submit button looks like this: 在您的代码中,“提交”按钮如下所示:

<td><input type= "submit" value="Next" onclick="checkOrder()" ><input type="hidden" name="submitted" value ="true" /></td>

Please change it to: 请更改为:

<td><input type= "submit" value="Next" onclick="return checkOrder()" ><input type="hidden" name="submitted" value ="true" /></td> . <td><input type= "submit" value="Next" onclick="return checkOrder()" ><input type="hidden" name="submitted" value ="true" /></td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript:onclick函数工作一次然后页面恢复为原始 - Javascript: onclick function works once then page reverts back to original Javascript document.write()定向到另一个页面 - Javascript document.write() directing to another page 无法进入首页,总是回到登录页面 - Can't enter the home page, always directing back to login page 为什么浏览器的后退按钮不指向最后浏览的页面? - why is browser the back button not directing to the last viewed page? 用PHP构造的JavaScript onClick函数在ajax响应中不起作用 - JavaScript onClick function constructed in PHP does not work in the ajax response back 通过在超链接中使用 onClick 调用 javascript 函数 - Calling a javascript function by using onClick in a hyperlink 如何在php / jquery(javascript)中创建一个将您定向到另一个页面的按钮? - How to make a button that is directing you to another page, in php/Jquery(javascript)? 如果输入不正确,如何避免函数定向到另一个页面 - How to avoid a function directing to another page if an entry is incorrect 如何生成一个使用表单自动定向到根文件夹的php页面? - How to generate a php page automatically directing into the root folder using a form? 使用Javascript onClick执行PHP功能而无需刷新页面 - Execute PHP function with Javascript onClick without page refresh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM