javascript - Disable a h:commandButton when h:inputText has no value -


i have 2 h:inputtext textboxes , h:commandbutton. how can disable button in case there no value in either of text box? how disable other text box in case have value in 1 of text box. please find sample code below:

<h:form id="myform">         <h:inputtext id="first" value=#{mybean.first}></h:inputtext>     <h:inputtext id="second" value=#{mybean.second}></h:inputtext>     <h:commandbutton id="submit" action="#{mybean.submit}" value="submit"/> </h:form> 

javascript:

document.getelementbyid("myform:first").onkeyup = function() {     if (this.value.length > 0) {         document.getelementbyid("myform:second").disabled = true;         document.getelementbyid("myform:submit").disabled = false;     } else {         document.getelementbyid("myform:second").disabled = false;         document.getelementbyid("myform:submit").disabled = true;     } }; document.getelementbyid("myform:second").onkeyup = function() {     if (this.value.length > 0) {         document.getelementbyid("myform:first").disabled = true;         document.getelementbyid("myform:submit").disabled = false;     } else {         document.getelementbyid("myform:first").disabled = false;         document.getelementbyid("myform:submit").disabled = true;     } }; 

the problem here works fine, have click outside once enable/disable button. there anyway button gets enabled automatically , other text box gets disabled moment data entered 1 of text boxes?

onload or directly in commandbutton tag keep button disabled="true". implement onchange or onblur method inputext , set style commandbutton disable='false'


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -