简体   繁体   English

获取所选div的值并使用php转到下一页

[英]Get value of selected div and carry to the next page with php

I've trying to set up a multiple page donation form. 我试图建立一个多页捐赠表格。 I've got it set up where a user can select from a few different boxes that all have different amounts of money in them. 我已经设置好了,用户可以从几个不同的盒子中进行选择,每个盒子中都有不同的金额。 What I want is for it to carry the value of the selected box to the next page via a php session variable. 我想要的是通过php会话变量将所选框的值携带到下一页。 I have an input box that that actually enter text into that I figured out just fine but I just can't figure out how to get the value of the boxes. 我有一个实际上可以输入文本的输入框,我认为还不错,但是我无法弄清楚如何获得这些框的价值。 Thanks. 谢谢。

<form role="form" action="donation.php">
    <div class="donate-box col-xs-8 col-xs-offset-2">
        <div class="donate-amounts">
        <ul id="amounts">
        <a href="#"><li>$15</li></a>
        <a href="#"><li>$25</li></a>
        <a href="#"><li>$50</li></a>
        <a href="#"><li>$100</li></a>
        <a href="#"><li>$200</li></a>
        </ul>
        </div><!-- End donate amounts -->
        <div class="donate-other">
            <div class="form-group">
                <label for="otheramount">Other</label>
                <input type="number" class="form-control" id="otheramount" placeholder="$" name="otheramount">
            </div>
        </div><!-- End donate other -->
        <div class="donate-month">
            <label for="monthly">Monthly</label>
            <div id="donate-month-check" class="donate-checkbox check-blank">
            <div id="month-check-on" style="display: none;"><img src="img/check.png"></div>
            </div>


        </div><!-- End donate month -->

        <div class="donate-one-time">
            <label for="one">One Time</label>
            <div id="donate-one-check" class="donate-checkbox check-blank">
            <div id="one-check-on" style="display: none;"><img src="img/check.png"></div>
            </div>                      
        </div><!-- End donate one time -->


        <div class="donate-submit">
            <button type="submit" class="btn btn-default donate-button">Donate Now</button>
        </div>

    </form>


$(function money () {
        $('li').click(function () {
            $('#amounts li').removeClass('clicked');
            $('.donate-other').removeClass('clicked');
            $(this).addClass('clicked');
        });

        $('.donate-other').click(function () {
            $('#amounts li').removeClass('clicked');
            $(this).addClass('clicked');
        });

        $('#donate-month-check').click(function () {
            $('#one-check-on').hide();
            $('#month-check-on').toggle();
        });

         $('#donate-one-check').click(function () {
            $('#month-check-on').hide();
            $('#one-check-on').toggle();
        });

        $('#amounts li').click(function() { 
            $('#otheramount').val('0');

        })

    });
<div class="donate-amounts">
    <ul id="amounts">   
    <a href="your_url?amount=15"><li>$15</li></a>

your_url.php your_url.php

($_GET["amount"]) 

You could pass the data by a GET Request: 您可以通过GET请求传递数据:

<div class="donate-amounts">
    <ul id="amounts">
        <a href="page.php?quantity=15"><li>$15</li></a>
        <a href="page.php?quantity=25"><li>$25</li></a>
        <a href="page.php?quantity=50"><li>$50</li></a>
        <a href="page.php?quantity=100"><li>$100</li></a>
        <a href="page.php?quantity=200"><li>$200</li></a>
    </ul>

and then in the page.php get the quantity variable: 然后在page.php中获取数量变量:

<?
$quantity = $_GET['quantity'];
?>

Is this what you want? 这是你想要的吗? Here is the fiddle that I created: http://jsfiddle.net/56BCe/ 这是我创建的小提琴: http : //jsfiddle.net/56BCe/

    $('#amounts li').click(function() { 
        $('#otheramount').val($(this).text());
    })

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM