cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript enabling and using JS methods on TextEdit component

Former Member
0 Kudos

Hello Friends:

I am working to display data using TableView component.

In each row, one of the cell contains a group of radio

buttons and an other cell contains TextEdit component.

For an event on the group of radio buttons, the TextEdit

should flip editable to non-editable and vice-versa.

I am using the TextEdit attribute method,

<b>setJsObjectNeeded(true)</b>

to expose the JavaScript methods of the component.

I am using the following bits of code for accessing the

TextEdit JavaScript functionality.

var funcName = htmlb_formid+"_getHtmlbElementId";
func = window[funcName];
var text_edit_comp = eval(func(id_of_textedit));
<b>text_edit_comp.setEnabled()</b>;

Whole thing works as planned, but it is not possible to

disable or enable the TextEdit component using the

JavaScript, as shown above.

In the portal documentation, the JavaScript object

methods were mentioned only for certain components, NOT

including TextEdit !!

If I replace TextEdit with InputField, it works perfectly

as like needed.

How to hack it to work for TextEdit ?

Thank you very much for your kind answers.

Prasad Nutalapati

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Prasad,

You could do the following if you know the id of the textedit.

var elem = document.getElementById('htmlb_1058_htmlb_471_1');
elem.disabled = true;

Former Member
0 Kudos

I did use the suggestion. No use.

When I say,

......
var textedit = eval(func("<id-of-the-textedit-from-java"));

I am getting the object reference.

When I say,

<b>var id = textedit.id;
var elem = document.getElementById(id);</b>

I am getting the HTML name/id and object of the text edit.

Now when I use JS methods and properties,

alert("type="+elem.type);
alert("name="+elem.name);

I get them back correctly.

Then when I say,

<b>alert("disable ?"+ document.forms[0].elements[elem.name].disabled;</b>

I am getting answer as 'false' which is not correct. It

is initially disabled, when I defined with Java.

And subsequently, when I say,

<b>document.forms[0].elements[elem.name].disabled = false;</b>

It didn't affect it at all.

If I try to use the JS methods provided by Portal, like..

<b>textedit.setEnabled();</b>

It is giving an JS error saying that the object doesn't

have that method.

Former Member
0 Kudos

Hi Prasad,

You need to set the value to <b>true</b> for textedit to be disabled.

PS: Please reward points for helpful answer or problem resolved. thank you.

Prakash

Message was edited by: Prakash Singh

Former Member
0 Kudos

Prasad,

Here is a solution for you.

var elem = document.getElementById('htmlb_815_htmlb_347_3_a1');
//this is to activate the input box
elem.readOnly=false;

Prakash

Former Member
0 Kudos

Prakash:

Thanks for your answer.

I used this code. Not good result.


<SCRIPT LANGUAGE="Javascript1.2" > 
     function ManagerAction(arg){
       var myarray = arg.split("~");
      var id = "reason~"+myarray[1]+"~"+(parseInt(myarray[2])+1);
      var funcName = htmlb_formid+"_getHtmlbElementId";
      func = window[funcName];
      var textedit = eval(func(id));
      var comp = document.getElementById(textedit.id); 
     if(comp != null){
       alert(comp.type); // I am getting 'textedit'
       alert(comp.name); // I am getting like 'htmlb_..'
       alert(comp.readonly); // getting 'undefined'
       comp.readonly = false;
       alert(comp.readonly); // 
    }else{
       alert("Null Component");
    }
        return true;  
    }
</script>

Former Member
0 Kudos

Prasad,

You need to do the following. If you post your JSP then i could tell you where to put it.

Add the following code to your JSP to get the id of your component.

<% String id = this.getPageContext().getParamIdForComponent('xxxx'); %>

Your javascript should look like following.


var elem = document.getElementById('<%=id%>');
//this is to activate the input box
elem.readOnly=false;

PS: Please reward points for helpful answer or problem resolved.

Message was edited by: Prakash Singh

Former Member
0 Kudos

Prasad,

I see your problem.

comp.readonly = false;

should be

comp.readOnly = false;

Former Member
0 Kudos

Thank you very much Prakash !!

It solved it.

There is a small misleading thing in the display.

Even when the TextEdit is enabled, i.e., writable, it's

background color doesn't change from dull gray. If you

see it with out typing in it, you would not believe it is

NOT a disabled field !!

BTW, you did a great help today,

Prasad Nutalapati

Answers (0)