OBJECT EXPECTED WHEN I USE STRUTS IN INNERHTML

Hello, i began to use javascript recently and I'm receiving an javascript error "OBJECT EXPECTED" when i test my function:

function inserirlinha()
            {
                alert("entrei na função inserir linha.");
                var table=document.getElementById('tabelaLigacoesMultiplas');
                alert("tabela = "+table);
                var newRow=table.insertRow(table.rows.length);
                alert("nº linhas da tabela = "+table.rows.length);
                alert("table.rows[0].cells.length");
                for(var i=0;i<table.rows[0].cells.length;i++){
                   alert("entrei no ciclo for");
                   var cell=newRow.insertCell(i);
                   switch (i) {
                     case 0: {
                      cell.className="hand";
                      cell.align="center";
                      cell.onclick="eventOnload();";
                      cell.innerHTML="<img src='./images/right.gif'>";
                      alert("i ="+i);  
                      break;
                     }                      
                     case 1: {                                    
                      //cell.innerHTML="<textarea name='teste' id='teste' width='50px'></textarea>";
                      cell.innerHTML="<html:form action='/LigacoesMultiplasPorCamada.do'    
target='iFrameTabelaLigacoesMultiplasPorCamada'><html:text name='formLigacoesMultiplasCamadaIFrame' property='nomeLigacao' styleClass='SubFormTextbox' maxlength='10' disabled='true'></html:text></html:form>";
                      //cell.innerHTML="<html:text name='formLigacoesMultiplasCamadaIFrame' property='nomeLigacao' styleClass='SubFormTextbox' maxlength='10' disabled='true'></html:text>";
                     // alert("i ="+i);
                     // alert("cell.innerHTML");
                     // break;                    
                     }
                     default:
                      alert("Em desenvolvimento");
                   } //switch  
                } //for        
            } //inserirlinha


The error occurs at line : "cell.innerHTML="<html:form action='/LigacoesMultiplasPorCamada.do' ....."~

Can anyone help me with this?

Thanks,
Nuno
NUNOPALMAAsked:
Who is Participating?
 
enachemcCommented:
new_obj = document.createElement('text')

shouldn't this be  
new_obj = document.createElement('input');
new_obj.type="text";

?
0
 
smidgie82Commented:
Hi NUNOPALMA,

What you need to do instead of trying to manipulate the innerHtml element, is use Javascript to manipulate the DOM.  For instance:

var parent_obj = document.getElementById('the_cell')
var new_obj = document.createElement('form')
new_obj.target='iFrameTabelLigacoesMultiplasPorCamada'
new_obj.action='/LigacoesMultiplasPorCamada.do'
parent_obj.appendChild(new_obj)

parent_obj = new_obj
new_obj = document.createElement('text')
...
parent_obj.appendChild(new_obj)


Cheers!
0
 
enachemcCommented:
The line "cell.innerHTML="<html:form action='/LigacoesMultiplasPorCamada.do' ....."~ will by transformed by the JSP and will look different in the transformed HTML code, perhaps it would span multiple lines (but you define it in a string that does not span multiple lines). To see exactly what happens, use the HTML generated by the JSP (View Source from your browser).
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
NUNOPALMAAuthor Commented:
I tryed to manipulate the DOM as smidgie82 told me and now i have a new javascript error:

Unexpected call to method or property access at line " var new_obj = document.createElement("html:form")"

"html:form" is a struts tag

Here is my new function:

function inserirlinha()
            {
                     
                alert("entrei na função inserir linha.");
                var table=document.getElementById('tabelaLigacoesMultiplas');
                alert("tabela = "+table);
                var newRow=table.insertRow(table.rows.length);
                alert("nº linhas da tabela = "+table.rows.length);
                alert("table.rows[0].cells.length");
                for(var i=0;i<table.rows[0].cells.length;i++){
                   alert("entrei no ciclo for, i="+i);
                   var cell=newRow.insertCell(i);
                   switch (i) {
                     case 0: {  
                      //cell.id="the_cell";            
                      cell.className="hand";
                      cell.align="center";
                      cell.onclick="eventOnload();";
                      cell.innerHTML="<img src='./images/right.gif'>";
                      alert("i ="+i);  
                      break;
                     }                      
                     case 1: {
                     //cell.id="the_cell";
                     alert("i ="+i);
                     var parent_obj = cell    
                     var new_obj = document.createElement("html:form")
                     new_obj.target='iFrameTabelLigacoesMultiplasPorCamada'
                     new_obj.action='/LigacoesMultiplasPorCamada.do'
                     parent_obj.appendChild(new_obj)

                     parent_obj = new_obj
                     new_obj = document.createElement('textarea')
                     new_obj.name='teste'
                     new_obj.id='teste'  
                     new_obj.styleClass='SubFormTextbox'
                     parent_obj.appendChild(new_obj)                              
                     alert("i ="+i)
                     alert("new_obj ="+new_obj)
                     break;                    
                     }
                     default:
                      alert("Em desenvolvimento");
                   } //switch  
                } //for        
            } //inserirlinha
0
 
enachemcCommented:
This is because html:form is not an HTML tag, it is an Struts tag. This tag will be interpreted by Struts and will output HTML tags. You probably should use the HTML "form" tag.
0
 
NUNOPALMAAuthor Commented:
I tried to use the HTML "form" tag instead of the Struts "html:form" tag and i receive no error but it doesn't display the textbox in the screen

Here it is my changed code:

....

case 1: {
                     alert("i ="+i);
                     var parent_obj = cell     //document.getElementById('the_cell')
                     var new_obj = document.createElement("form")
                     new_obj.target='iFrameTabelLigacoesMultiplasPorCamada'
                     new_obj.action='/LigacoesMultiplasPorCamada.do'
                     parent_obj.appendChild(new_obj)

                     parent_obj = new_obj
                     new_obj = document.createElement('text')
                     new_obj.name='formLigacoesMultiplasCamadaIFrame'
                     new_obj.property='nomeLigacao'
                     new_obj.styleClass='SubFormTextbox'
                     new_obj.maxlength='10'  
                     new_obj.disabled='false'
                     parent_obj.appendChild(new_obj)
                     alert("i ="+i)
                     break;                    
                     }

Thanks,
Nuno
0
 
gops1Commented:
Even if you are struts, finally when it is rendered in a page it becomes a normal HTML tags, so do not use the struts tag, use simple HTML tags.
0
 
smidgie82Commented:
enachemc,

You're absolutely right.  My mistake.  

document.createElement('text') line should be replaced by new_obj = document.createElement('input'); new_obj.type = 'text';

Good call.

~Dathan
0
 
NUNOPALMAAuthor Commented:
thank you enachemc, you solved my problem. but instead of
new_obj = document.createElement('input');
we must use
new_obj = document.createElement("input");

0
 
enachemcCommented:
why ?
0
 
NUNOPALMAAuthor Commented:
i don't know. I just tryed and it resulted with " "
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.