Hi i want a textbox enable or disable dependig of a checkbox status
i have this code but nothing happens i´ve tried using others find methods.
document.getElementById('j_idt6:docName')
and
('j_idt6:docName')
But doesn´t works.
This is my whole code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title></title>
</h:head>
<h:body>
<script type="text/javascript"
src="http://code.jquery.com/jquery-git.js"></script>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('#j_idt6\\:singleDoc').change( function() {
var isChecked = this.checked;
if(isChecked) {
$(this).parents("tr:eq(0)").find('#j_idt6\\:docName').prop("disabled",true);
} else {
$(this).parents("tr:eq(0)").find('#j_idt6\\:docName').prop("disabled",false);
}
});
});//]]>
</script>
<h:form>
<p:panel id="panel" header="Test">
<h:panelGrid columns="1" cellpadding="5">
<p:outputLabel for="singleDoc" id="msgSingleDoc"
value="Is a single document." />
<p:selectBooleanCheckbox id="singleDoc" />
<p:outputLabel for="docName" value="Name of the document" />
<p:inputText id="docName" required="false" />
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
I found a different way to find the elements here http://www.mkyong.com/jsf2/primefaces/how-to-get-jsf-id-via-jquery/
I´m using Primefaces 5
but still nothing happens
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ORC Sysmar</title>
<script type="text/javascript"
src="http://code.jquery.com/jquery-git.js"></script>
</h:head>
<h:body>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$(PrimeFaces.escapeClientId('formulario:singleDoc')).change( function() {
var isChecked = this.checked;
if(isChecked) {
$(this).parents("tr:eq(0)").find(PrimeFaces.escapeClientId('formulario:docName')).prop("disabled",true);
} else {
$(this).parents("tr:eq(0)").find(PrimeFaces.escapeClientId('formulario:docName')).prop("disabled",false);
}
});
});//]]>
</script>
<h:form id="formulario">
<p:panel id="panel" header="Test">
<h:panelGrid columns="1" cellpadding="5">
<p:outputLabel for="singleDoc" id="msgSingleDoc"
value="Is a single document." />
<p:selectBooleanCheckbox id="singleDoc" />
<p:outputLabel for="docName" value="Name of the document" />
<p:inputText id="docName" required="false" />
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
Thanks in advance for your time and answers