469,277 Members | 1,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,277 developers. It's quick & easy.

createElement('input') onblur event does not return function value

Hi, I'm pretty new to javascript,Ajax, DHTML so you'll have to forgive me....

I have some code that creates a table row dynamically. The table row and associated cells creates without issue. The problem though is that the call to onblur event is not returning any value from the function when called. Yet when I execute an alert statment within the function, I can see the function has been called and the return value of the function. Also when I use the function on a a cell that is not dynamically created, it works as designed. Any help would be greatly appreciated. Thank you in advance!!

Expand|Select|Wrap|Line Numbers
  1. function addrow()
  2. ...
  3.  
  4. var cellTen = row.insertCell(9); 
  5. var disamt = document.createElement('input'); 
  6. disamt.type = 'text'; 
  7. disamt.name = 'Dist_amt' + iteration; 
  8. disamt.id = 'Dist_amt' + iteration; 
  9. disamt.size = 25;
  10. disamt.maxLength = 25;
  11. disamt.style.textAlign = "right";
  12. disamt.onblur = (function (iteration){return function() {formatCurrency(this.value);};})(iteration);        
  13. cellTen.appendChild(disamt);
  14.  
  15. //thanks - Cyanide_7 (leo7278@hotmail.com) 
  16. function formatCurrency(num) {
  17. num = num.toString().replace(/\$|\,/g,'');
  18. if(isNaN(num))
  19. num = "0"; 
  20. sign = (num == (num = Math.abs(num)));
  21. num = Math.floor(num*100+0.50000000001);
  22. cents = num%100;
  23. num = Math.floor(num/100).toString(); 
  24. if(cents<10)
  25. cents = "0" + cents;
  26. for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  27. num = num.substring(0,num.length-(4*i+3))+','+
  28. num.substring(num.length-(4*i+3));
  29. alert((((sign)?'':'-') + '$' + num + '.' + cents)); 
  30. return (((sign)?'':'-') + '$' + num + '.' + cents);
  31. }
  32.  
  33.  
Feb 13 '12 #1
1 2516
Dormilich
8,651 Expert Mod 8TB
The problem though is that the call to onblur event is not returning any value from the function when called.
why should it? you didn't define a return value.
Expand|Select|Wrap|Line Numbers
  1. // what is attached to the blur event
  2. function() {formatCurrency(this.value);}
besides that, what good does a return value do in this situation, you don't have anything that could accept the return value?
Feb 14 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Evan Wong | last post: by
2 posts views Thread by andyalean | last post: by
16 posts views Thread by Geoff Cox | last post: by
5 posts views Thread by gimme_this_gimme_that | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.