How to copy a value within a span

2

I need to copy a value from within a span that is generated by a slider, it always changes the slider whenever it changes. Is there any way I can put it inside a value of an an input?

I tried this and it did not work:

<h4>Valor do consórcio: <span class="slider-value quote-form-element valor-carro1" data-name="Valor | Automóvel" name="Valor" data-slider-id="consorcio-auto">R$ <span id="THAT_VALUE"></span></span>
                            </h4>
<div class="slider" data-slider-min="20000" data-slider-max="100000" data-slider-start="23192" data-slider-step="1000" data-slider-id="consorcio-auto"></div>

<h4>Seus dados:</h4>
<input type="hidden" id="THAT_FIELD" name="THAT_FIELD" value="" />
<h4>Seus dados:</h4>
<input type="hidden" id="valorcarro" name="valorcarro" value=""  />

Script:

$(function(){
var valorcarro = $('#THAT_VALUE').html();
$('#THAT_FIELD').val(valorcarro);
});

The problem is that with this script the value in the input is blank because the span text is only generated afterwards, and the user can still change it.

Example on this page on the "Simulation" button in the menu.

    
asked by anonymous 27.10.2016 / 18:21

1 answer

1

You can use the following to get the value of the slider:

<!-- adicionei um id para simplificar o exemplo -->
<div class="slider" id="slider" ...... >


$('#THAT_FIELD').val($('#slider').slider('option', 'value'));
    
27.10.2016 / 18:32