Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Javascript error in JSF  RSS feed

 
yuvaraaj mohan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

We are using JSF Trinidad in our application. We have a requirement where we need a javascript snippet something similar to the one mentioned below.

function swap(id){
alert(eval(id).innerHTML );
}

id---> Id of the element


This works fine in normal JSP. But in JSF , it doesn't fetch the required result. Can somebody tell me where we are making mistake?

TIA,
Yuvaraj.
 
Srini Mutpur
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Does the "id" property which you are trying to fetch the innerHTML values included in some form(<h:form id="myid"> or <a4j:form id="myid">) elements ? If it so then you have to pass the complete name to the script function.

The id value should be <myFormId>:<myAttribId>.

Ex: swap('myId:myAttrib');
 
yuvaraaj mohan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Srini,
Thanks for writing in. The problem is that, since we are using JSF, the id's passed to the javascript function is a unique id (something similar to j_id_jsp_123456_92:1:td) generated by JSF itself. When i pass this id to eval() function, it gets failed. I tried this using normal HTML and found that the problem is basically with the ':' character which is present in the id attribute. So i am looking for some way by which i can change the internal id generated by JSF. Is this possible?

Yuvaraj.
 
Brajendra Mathema
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

provide form id by yourself : like <h:form id="myform"> and provide the element id :like <h:inputText id="myInputText>



access the element as : documnt.getElementById("myform:myInputText");

to get the element id for access in javascript you can view the html source , you will find it id of the element as myform:myInputText
access the element using that id

thankyou
brajen
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!