Reputation: 79
I am trying to get the contents of my SPAN value into a text INPUT box.
<script>
function myFunction()
{
$('input[name=exp_total_copy]').val($('[name=document.getElementById("grandtotal").innerText]').val());
}
I also tried it as: $('input[name=exp_total_copy]').val($('document.getElementById("grandtotal").innerText').val());
Textbox:
<input type="text" name="exp_total_copy" id="exp_total_copy">
Span:
<span class="description" for="element_7"><b>Total: $</b><span name="grandtotal" id="grandtotal">0.00</span></span>
So basically when one of my textboxes onClick occurs, the MyFunction() is activated and supposed to grab the contents of the span of grandtotal and insert it into the textbox of exp_total_copy.
Upvotes: 0
Views: 265
Reputation: 56
You just complicated it more. what work should be
function myFunction(){
var spanText = $("#grandtotal").text();
$("input[name=exp_total_copy]").val(spanText);
}
OR
//using the Id attributes
function myFunction(){
var spanText = $('#grandtotal').text();
$('#exp_total_copy').val(spanText);
}
Upvotes: 0
Reputation: 33399
You're not executing the query; you're giving it as a string.
$('input[name=exp_total_copy]').val($('[name='+document.getElementById("grandtotal").innerText+']').val());
But why bother with the DOM query? Just use jQuery:
$('input[name=exp_total_copy]').val($('[name='+$("#grandtotal").text()+']').val());
Upvotes: 0