Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OBJECT EXPECTED WHEN I USE STRUTS IN INNERHTML

Posted on 2006-07-11
11
Medium Priority
?
708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

715 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