Calling Javascript function within innerHTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsherp
    New Member
    • May 2007
    • 34

    Calling Javascript function within innerHTML

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

    example:

    Code:
    var someelement =  document.createElement("input"); 
    var someelement2  =  document.createElement("input"); 
    
    function test(str) { var str2 = test.substring(0,4); 
                               return str2; }
    
    someelement.ondblclick=function(){ 
           document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\'test(this.value)\' >';
    }
    
    \\I think this works if the quotes are escaped properly, but i haven't been \\successful in doing it.
    
    someelement.ondblclick=function(){ 
           document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\' '+test(+' this.value ' +) ' +\' >';
    }
    any help will be much appreciated.
  • Ferris
    New Member
    • Oct 2007
    • 101

    #2
    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.

    Comment

    • gsherp
      New Member
      • May 2007
      • 34

      #3
      Thanks for the reply.

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

      Code:
      document.getElementById(something).innerHTML = data + '<input name=datafield id=datafield value=data class=nosee>';
      This seems to work for me, so i decided to just go with this method.

      Comment

      Working...