469,926 Members | 2,259 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Calling Javascript function within innerHTML

34
Is there anyway to call a javascript function within an innerHTML call?

example:

Expand|Select|Wrap|Line Numbers
  1. var someelement =  document.createElement("input"); 
  2. var someelement2  =  document.createElement("input"); 
  3.  
  4. function test(str) { var str2 = test.substring(0,4); 
  5.                            return str2; }
  6.  
  7. someelement.ondblclick=function(){ 
  8.        document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\'test(this.value)\' >';
  9. }
  10.  
  11. \\I think this works if the quotes are escaped properly, but i haven't been \\successful in doing it.
  12.  
  13. someelement.ondblclick=function(){ 
  14.        document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\' '+test(+' this.value ' +) ' +\' >';
  15. }
  16.  
  17.  
any help will be much appreciated.
Dec 7 '07 #1
2 6469
Ferris
101 100+
Hi:

1st: input element can't use innerHTML.Only div element can use innerHTML.

2st: you create 2 input elements by using javascript,but you didn't add it into document.

I can't understand what you want to do,so tell me what you want,and I can post the code you want.
Dec 8 '07 #2
gsherp
34
Thanks for the reply.

I got around this problem by using an invisible input field in the innerHTML

Expand|Select|Wrap|Line Numbers
  1.  
  2. document.getElementById(something).innerHTML = data + '<input name=datafield id=datafield value=data class=nosee>';
  3.  
This seems to work for me, so i decided to just go with this method.
Dec 11 '07 #3

Post your reply

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

By using this site, you agree to our Privacy Policy and Terms of Use.