javascript - Send data out of visible form only -


i have 2 divs containing same input fields. when enter vales in both div fields, values submitted. want is, value of selected div (using radio button) should pass. appreciated :-)

$(document).ready(function() {      console.log('called');      $('input[type=radio][name=cancel_policy]').change(function() {      if (this.value == '0') {        $("#fixedpolicydiv").css("display", "block");        $("#percentagepolicydiv").css("display", "none");        $("#percentagepolicydiv").get(0).reset();        } else if (this.value == '1') {        $("#fixedpolicydiv").css("display", "none");        $("#fixedpolicydiv").get(0).reset();        $("#percentagepolicydiv").css("display", "block");      }    });    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <label class="custom-control custom-control-primary custom-radio">    <input class="custom-control-input" type="radio" name="cancel_policy" value="0"> <span class="custom-control-indicator"></span>    <span class="custom-control-label">fixed price</span>   </label>    <label class="custom-control custom-control-primary custom-radio">    <input class="custom-control-input" type="radio" name="cancel_policy" value="1"> <span class="custom-control-indicator"></span>    <span class="custom-control-label">percentage wise</span>   </label>    <div id="fixedpolicydiv" style="display:none;">    <div class="form-group">      <div class="col-lg-11 col-lg-offset-1">        <div class="table-responsive">          <table class="table" id='cancel_tbl'>            <tr>              <td width='30%'>days</td>              <td width='30%'>amount</td>              <td>&nbsp;</td>            </tr>            <tr>              <td>                <input type="number" name="cancel_policy_days[]" class="form-control" placeholder="days" value="<?= set_value('cancel_policy_days[]') ?>" required="required" />              </td>              <td>                <input type="number" name="cancel_policy_amount[]" class="form-control" placeholder="cancellation amount" value="<?= set_value('cancel_policy_amount[]') ?>" required="required" />              </td>              <td>&nbsp;</td>            </tr>            <tr>              <td colspan="6" align="center">                <input type="button" value="add more" id="cancel_addmorebtn1" class="btn btn-outline-info">              </td>            </tr>          </table>          </div>      </div>    </div>  </div>      <div id="percentagepolicydiv" style="display:none;">    <div class="form-group">      <div class="col-lg-11 col-lg-offset-1">        <div class="table-responsive">          <table class="table" id='cancel_tb2'>            <tr>              <td width='30%'>days</td>              <td width='30%'>percentage</td>              <td>&nbsp;</td>            </tr>            <tr>              <td>                <input type="number" name="cancel_policy_days[]" class="form-control" placeholder="days" value="<?= set_value('cancel_policy_days[]') ?>" required="required" />              </td>              <td>                <input type="number" name="cancel_policy_amount[]" class="form-control" placeholder="cancellation percentage" value="<?= set_value('cancel_policy_amount[]') ?>" required="required" />              </td>              <td>&nbsp;</td>            </tr>            <tr>              <td colspan="6" align="center">                <input type="button" value="add more" id="cancel_addmorebtn2" class="btn btn-outline-info">              </td>            </tr>          </table>          </div>      </div>    </div>  </div>

you can add disabled property inputs not want sent. exemple :

$("#percentagepolicydiv").find('input').prop('disabled'); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -