How to set value of an input using jQuery?
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, an开发者_StackOverflow中文版y idea about how to implement this behavior are welcomed.
Regards, Radu
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
Try replacing the following line:
if ($(this).val() == true)
with
if ($(this).val() == 'true')
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论