views:

163

answers:

3

Hi ,

I am trying to change the value of an input depending on selection from a combo box, so is user selects "Yes" from combo box the input should contain "test" value and than if user selects "No" the input should be empty , "test" value remove from it.

I tryed to do it runing the following code:

<h:inputText id="myInput" value="aaa" styleClass="myInputStyleClass" />  
<h:selectOneMenu id="myComboBox" value="#{bean.boolVal}">  
    <f:selectItem itemLabel="#{m.n}" itemValue="false" />  
    <f:selectItem itemLabel="#{m.y}" itemValue="true" />  
</h:selectOneMenu>  

<rich:jQuery timing="onload" selector="#myComboBox" query="change(  
  function(){   
  if ($(this).val() == true) {  
   $('.myInputStyleClass').val('test');  
  }  
 } )"  />  

Running it in this version the javascript error "Object doesn't support this property or method" still occurs.(when i change selection in combo box)

After removing

if ($(this).val() == true)

condtion and additionals { } the first javascript error is gone but another is raised saying "null is 'null' or not an object", when i change selection in combo box.

I am not sure if only rich faces jars (3.3.2) had support for this jQuery implementatios like using "$" and other methods (may be some jQuery libraries are nedded), this could be one reason why this is not working in my opinion.

Please, any idea about how to implement this behavior are welcomed.

Regards, Radu

+1  A: 

Use if ($(this).val() == 'true') as the value will be a string, not a boolean and thus the comparison will be always false:

js> 'false' == true
false
js> 'true' == true
false
ThiefMaster
Hi, Thank you for your fast reply, ok so it is a comparison issue, can this be solved somehow ? Regards,Radu
Radu
A: 

Try replacing the following line:

if ($(this).val() == true)

with

if ($(this).val() == 'true')
MarkB29
A: 

true should be included in single quote as 'true' in the logical statement

Ashu