添加隐藏字段,包括当前提交字段值,并作为隐藏字段发送到下一页

时间:2013-10-23 05:08:02

标签: jquery html forms

这个表单实际上是获取一些输入字段,如下所示。

我需要添加输入(隐藏)字段值和我从custom12获取的值,并在隐藏字段中作为自定义13发送到下一页。怎么做

<form name="q9" id="submitDetails" action="pandora.do" method="post" class="form-horizontal">

<input type="hidden" name="cutom4" value="1" class="Qty">
<input type="hidden" name="cutom5" value="2" class="Qty">
<input type="hidden" name="cutom6" value="3" class="Qty">
<input type="hidden" name="cutom7" value="5" class="Qty">
<input type="hidden" name="cutom8" value="1" class="Qty">
<input type="hidden" name="cutom9" value="9" class="Qty">
<input type="hidden" name="cutom10" value="8" class="Qty">
<input type="hidden" name="cutom11" value="10" class="Qty">         

          <fieldset class="questionsForm">
            <div class="form-group">
              <div class="col-xs-10">
                <div class="radio">
                  <input name="custom12" id="custom12A" value="1" type="radio" class="styled myClass prettyCheckable">
                  <label for="custom12A">I love what I love – that will never change </label>
                </div>
                <div class="radio">
                  <input name="custom12" id="custom12B" value="2" type="radio" class="styled myClass prettyCheckable">
                  <label for="custom12B">I keep an eye on the charts </label>
                </div>
                <div class="radio">
                  <input name="custom12" id="custom12C" value="3" type="radio" class="styled myClass prettyCheckable">
                  <label for="custom12C">I buy t-shirts, records and go to live shows if I like an artist. </label>
                </div>
                <div class="radio">
                  <input name="custom12" id="custom12D" value="4" type="radio" class="styled myClass prettyCheckable">
                  <label for="custom12D">I always know every word of every song and travel night and day for my artists.</label>
                </div>
              </div>
            </div>
            <div id="error_msg5">&nbsp;</div>

            <input type="hidden" name="cutom13" value="$entrantForm32399.custom13" id="custom13">           

            <div class="clearfix">&nbsp;</div>
            <!-- Button -->
            <div class="form-group nextButton">
              <div class="col-xs-10">
                <button id="submitDetails" name="submitDetails" class="btn btn-primary btnNext">NEXT</button>
              </div>
            </div>
          </fieldset>
        </form>

2 个答案:

答案 0 :(得分:1)

您可以使用localstorageCookies使用javascript将数据从一个页面发送到另一个页面。

$'#submitDetails').on('click',function(){
    localStorage.setItem('formData',$('#submitDetails').serialize());
    $('#submitDetails').submit();
    // set form data to local storage
});

阅读serialize()

或者,你可以试试这个,

首先更改id的{​​{1}},form必须为idunique和{{1}两者都有相同的button

form

答案 1 :(得分:0)

结束以下解决方案

$( "#submitDetails" ).submit(function( event ) {

    var c1 = parseInt($(this).find('input[name="custom4"]').val());
    var c2 = parseInt($(this).find('input[name="custom5"]').val());
    var c3 = parseInt($(this).find('input[name="custom6"]').val());
    var c4 = parseInt($(this).find('input[name="custom7"]').val());
    var c5 = parseInt($(this).find('input[name="custom8"]').val());
    var c6 = parseInt($(this).find('input[name="custom9"]').val());
    var c7 = parseInt($(this).find('input[name="custom10"]').val());
    var c8 = parseInt($(this).find('input[name="custom11"]').val());

    var radioInput = parseInt($(this).find('input[name="custom12"]:checked').val());

    var total = c1+c2+c3+c4+c5+c6+c7+c8+radioInput;

    $('#finalvalue').val(total);

    $test = $('#finalvalue').val();

});