I need to show a text result of an amount, and for this I'm using a javascript function "toWords". This function is working great when I use onInput or onClick, but I need to call this function when the document opens. So this is what I tried:
<div class="label-field-pair3-text-area">
<p id="demo"></p>
</div>
<script type='text/javascript'>
document.getElementById("demo").innerHTML = window.toWords("<%= @amount.to_f %>");
..... </script>
But this doesn't work. I also tried this:
j(document).ready( function(){ text_amount();});
function text_amount(){
var i= getElementbyId('payment_text');
i.val(toWords("<%= @amount.to_f %>"));}
And this:
<div class="label-field-pair3-text-area" id='payment_text' onload = "text_amount(150)">
But none of this worked, and nothing is displayed.
UPDATE: When I removed render :pdf from controller, it worked. So the problem is in running this function onLoad upon rendering my PDF file.
onloadcallback onbodytag?@amount.to_fmight be returning nothing.. try putting this and see<%= '1.0'.to_f %>instead of<%= @amount.to_f %>