Question

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);
Was it helpful?

Solution

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

You are referring to it by id. Add the id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top