Reputation: 6014
How Do I get the value of a span tag and send it into my form to another page?
<span id="subtotal"></span>
I need to send the content of my span tag subtotal to another page, I would like to save it into a hidden field, but I found no way to do this..
I used this, but no success!
function getTotal() {
return alert(document.getElementById('total').innerHTML);
}
Here goes the right function for those who need the answer! After I figured out the script ...
function getTotal() {
//document.write(document.getElementById('total').innerHTML);
var someValue = $(".total").text();
alert("Value is "+someValue);
//It cause to releoad the page and give me the parameter total
location.href="frmAdd.php?total=" + someValue;
}
Upvotes: 10
Views: 46143
Reputation: 69
The value of span is added to the input field of id="sub". you may use any events for assign values to hidden fields like click, change, submit, or you do as your logic .its an option.
$("#sub").val($("#subtotal").text());
<span id="subtotal"></span>
<input type="hidden" id="sub" >
Upvotes: 4
Reputation: 3326
Should'nt you be having subtotal
instead of total
there?
function getTotal() {
return alert(document.getElementById('subtotal').innerHTML);
}
Upvotes: 2
Reputation: 9456
You could try the .text()
method if you're using jQuery.
$("#subtotal").text();
Upvotes: 8