Pregunta

I have a span (#sum) which changes dynamically, adding up the values of selected options in a form. I want to append the text from this to the value of a hidden input field so I can email the figure.

So my html is

<span id="sum">£0.00</span>

and my hidden field is

<input type="hidden" name="total" value=""  />

But using jQuery that needs to read

<input type="hidden" name="total" value="[WHATEVER THE NUMBER IN THE SUM SPAN IS]"  />

Here is the jQuery I have so far:

var total = $('#sum').html();
    $('#total').val(total);
¿Fue útil?

Solución

<input name="total" type="hidden" id="total" value=""  />

You are referring to it by id. Add the id

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top