JQuery prefill form

Enter the invoice amount generated by the plugin on the page. I want to copy its identifier in the form field to pre-populate it.

<div id="invoicediv">$123.00</div> 

<div id="price"></div>
<br />
<form a`ction="https:/thecart.com" method="post" accept-charset="utf-8">  

<label>Donation Amount:</label><br>  
$<input id="txtBox" size="3" type="text" name="dollaramount">   
<input type="hidden" name="name" value="Donation">   
<input type="submit" value="Donate">  
</form> 

jQuery that works:

$('#price').html($('#invoicediv'));

but the form is not:

$('#txtBox').val($('#invoicediv'));​

I also want to remove the dollar sign before it copies itself to the form.

I have the following code so far at http://jsfiddle.net/yvTNc/24/ .

+5
source share
2 answers

You copy the jquery object inside val (), you need it $('#invoicediv').val()either .text()depending on what element it is. In this case you need$('#invoicediv').text()

Like this

$('#txtBox').val($('#invoicediv').text());​
+1
source

I am updating your code and watching

http://jsfiddle.net/yvTNc/25/

I changed this line $('#txtBox').val($('#invoicediv'));​

to

$('#txtBox').val($('#invoicediv').text().replace('$',''));​

+1
source

All Articles