Form not submitting hidden input

There is hidden input in code which must be TRY by default and be changeable using dropdown box. Code: HTML:

<div class="form-group">
            <label class="col-sm-3 control-label">Fiyat</label>
            <div class="col-sm-4 col-md-3 col-lg-2">
                <div class="input-group input-group-sm">
                    <input type="text" placeholder="Fiyat" class="form-control js-listing-price js-numeric" name="price.amount" />
                    <div class="input-group-btn btn-default">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <span class="js-currency-preview">TL</span>
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu pull-right">
                            <li><a data-value="TRY">TL</a></li>
                            <li><a data-value="USD">$</a></li>
                            <li><a data-value="EUR">€</a></li>
                        </ul>
                        <input type="hidden" value="TRY" class="js-listing-price-currency js-currency" name="price.currency">
                    </div>
                </div><!-- /input-group -->
            </div>
        </div>

Javascript:

$('.dropdown-menu').on('click', 'li a', function(e) {
    e.preventDefault();
    $('.js-currency-preview').text($(this).text());
    $('.js-listing-price-currency').val($(this).data('value'));
  });
};

All other fields are working except this js-currency field.

Answers:

Answer

As Backbone Binder can't see hidden changes in hidden inputs they mustn't change in page. It can be solved by adding trigger('change'); to the code:

$('.js-listing-price-currency').val($(this).data('value')).trigger('change');

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.