[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

OBJECT EXPECTED WHEN I USE STRUTS IN INNERHTML

Posted on 2006-07-11
11
Medium Priority
?
713 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:NUNOPALMA
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 9

Expert Comment

by:smidgie82
ID: 17083278
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
 
LVL 12

Expert Comment

by:enachemc
ID: 17088410
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
 

Author Comment

by:NUNOPALMA
ID: 17089176
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 12

Expert Comment

by:enachemc
ID: 17089216
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
 

Author Comment

by:NUNOPALMA
ID: 17089317
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
 
LVL 12

Accepted Solution

by:
enachemc earned 2000 total points
ID: 17089511
new_obj = document.createElement('text')

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

?
0
 
LVL 17

Expert Comment

by:gops1
ID: 17089916
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
 
LVL 9

Expert Comment

by:smidgie82
ID: 17090504
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
 

Author Comment

by:NUNOPALMA
ID: 17090561
thank you enachemc, you solved my problem. but instead of
new_obj = document.createElement('input');
we must use
new_obj = document.createElement("input");

0
 
LVL 12

Expert Comment

by:enachemc
ID: 17090614
why ?
0
 

Author Comment

by:NUNOPALMA
ID: 17092146
i don't know. I just tryed and it resulted with " "
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question