É o seguintee…eu tenho um cadastro no meu sistema e eu preciso fazer algumas validações nelee…e quero faazer com javascript…
mas eu nao consigo pegar os valores das inputText’s com o comando:
cara tambem estou com o mesmo problema.... é que assim para usar o document.getElementById("id_do_campo").value; vc tem que fazer o seguinte
no seu form vc deve colocar uma tag chamada prependId="false" pois os atributos filhos vao herdando os Id dos elementos pais ... tipo
<formid ="a"><textoid ="b"></form>
o codigo gerado disso fica algo como
<formid ="a"><textoid ="a:b"></form>
o texto por ser filho do form recebe o id do pai... ai colocando o prependId="false" no form não era para isso acontecer, mas comigo não esta dando certo tb =/
olha meu topico http://guj.com.br/posts/list/225851.java
Eu fiz um teste com o primeiro código q postei e o <[CDATA[…]]> realmente ficou sobrando pois o framework o colocou lá p/ mim. Eu ñ tenho certeza d quem fez isso, se foi Facelets, JSF, ou o próprio servidor. Agora, vc ao menos testou o ultimo código q postei? Eu o executei em servidor Glassfish v3.0.1 e funcionaou perfeitamente.
Schoker
nao deu certo…eu tentei todos os exemplos ai de cima…nenhuma deu certo…
se isso ajuda em alguma coisa, minha pagina é .jsp…
dev.rafael
Mesmo JSP o código deveria funcionar. Seria um problema postar o código da sua página p/ q eu possa dar uma olhada?
Schoker
tem partes estranhas no codigo rsrs…mas nem esquenta que sao testes rsrs…
<%@pagecontentType="text/html"pageEncoding="ISO-8859-1"%><%@taglibprefix="f"uri="http://java.sun.com/jsf/core"%><%@taglibprefix="h"uri="http://java.sun.com/jsf/html"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><f:subviewid="conteudo_lateral_direita"><html><head><metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"/><scripttype="text/javascript">$(document).ready(function(){$('#cadastrar').button();$('#cadastrar').click(function(){varnome=document.getElementById('formulario:nome_adm').value;alert(nome);});$('#novo').button({icons:{primary:'ui-icon-document'}});$('#editar').button({icons:{primary:'ui-icon-pencil'}});$('#excluir').button({icons:{primary:'ui-icon-trash'}});$('#conteudo').css('height','880px');$('#novo').click(function(){varxml="<administradora>\n\ <codigo>0</codigo>\n\ <nome>heitor</nome>\n\ <razaoSocial>razao</razaoSocial>\n\ <cnpj>12345678912345</cnpj>\n\ <rua>rua</rua>\n\ <bairro>bairro</bairro>\n\ <complemento>comlemento</complemento>\n\ <numero>62</numero>\n\ <cep>13339520</cep>\n\ <cidade>indaiatuba</cidade>\n\ <uf>SP</uf>\n\ <telefone>30160786</telefone>\n\ <ddd>19</ddd>\n\ <email>[email removido]</email>\n\ <site>site.com.br</site>\n\ <nomeResponsavel>heitor</nomeResponsavel>\n\ <telefoneResponsavel>12345678</telefoneResponsavel>\n\ <dddTelefoneResponsavel>19</dddTelefoneResponsavel>\n\ <celularResponsavel>12345678</celularResponsavel>\n\ <dddCelularResponsavel>19</dddCelularResponsavel>\n\ <nextelResponsavel>[telefone removido]</nextelResponsavel>\n\ <emailResponsavel>[email removido]</emailResponsavel>\n\ <usuarioPainel>dadasdas</usuarioPainel>\n\ <senhaPainel>dsadas</senhaPainel>\n\ <ultimoAcesso>2005-12-13 17:26:58.772 CET</ultimoAcesso>\n\ <dataCadastro>2005-12-13 17:26:58.772 CET</dataCadastro>\n\ <status>false</status>\n\ </administradora>";$.post("Servlet",{action:"cadastrar",bean:"Administradora",param:xml});alert("aqui");});});</script></head><body><divid="titulo"><h:outputTextvalue="Listagem de Usuários"/></div><h:formid="formulario"><divid="formulario"><h3style="margin-top: 0px;"><h:outputTextvalue="Informações da administradora"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="nome_adm"value="Nome:"/><h:inputTextid="nome_adm"value=""size="82"maxlength="50"/><h:outputLabelfor="razao_social_adm"value="Razão Social:"/><h:inputTextid="razao_social_adm"value=""size="82"maxlength="50"/><h:outputLabelfor="cnpj_adm"value="CNPJ:"/><h:inputTextid="cnpj_adm"value=""size="15"maxlength="14"/><h:outputLabelfor="rua_adm"value="Rua:"/><h:inputTextid="rua_adm"value=""size="70"maxlength="50"/><h:outputLabelfor="bairro_adm"value="Bairro:"/><h:inputTextid="bairro_adm"value=""size="70"maxlength="50"/><h:outputLabelfor="complemento_adm"value="Complemento:"/><h:inputTextid="complemento_adm"value=""size="82"maxlength="100"/><h:outputLabelfor="numero_adm"value="Número:"/><h:inputTextid="numero_adm"value=""size="5"maxlength="6"/><h:outputLabelfor="cep_adm"value="CEP:"/><h:inputTextid="cep_adm"value=""size="8"maxlength="9"/><h:outputLabelfor="cidade_adm"value="Cidade:"/><h:inputTextid="cidade_adm"value=""size="40"maxlength="40"/><h:outputLabelfor="estado_adm"value="Estado:"/><h:selectOneMenuid="estado_adm"><f:selectItemsvalue="#{usuario.estados}"/></h:selectOneMenu><h:outputLabelfor="telefone_adm"value="Telefone:"/><h:inputTextid="telefone_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="email_adm"value="Email:"/><h:inputTextid="email_adm"value=""size="60"maxlength="80"/><h:outputLabelfor="site_adm"value="Site:"/><h:inputTextid="site_adm"value=""size="60"maxlength="80"/></h:panelGrid><br/><h3><h:outputTextvalue="Informações do responsável"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="nome_resp_adm"value="Nome:"/><h:inputTextid="nome_resp_adm"value=""size="82"maxlength="40"/><h:outputLabelfor="telefone_resp_adm"value="Telefone:"/><h:inputTextid="telefone_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="celular_resp_adm"value="Celular:"/><h:inputTextid="celular_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="nextel_resp_adm"value="Nextel:"/><h:inputTextid="nextel_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="email_resp_adm"value="Email:"/><h:inputTextid="email_resp_adm"value=""size="60"maxlength="80"/></h:panelGrid><br/><h3><h:outputTextvalue="Informações da conta de usuário"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="usuario_adm"value="Usuário:"/><h:inputTextid="usuario_adm"value=""size="20"maxlength="40"/><h:outputLabelfor="senha_adm"value="Senha:"/><h:inputSecretid="senha_adm"value=""size="20"maxlength="40"/><h:outputLabelfor="confirmar_senha_adm"value="Confirmar senha:"/><h:inputSecretid="confirmar_senha_adm"value=""size="20"maxlength="40"/></h:panelGrid><br/><br/><aid="cadastrar"><h:outputTextvalue="Cadastrar"/></a></div></h:form></body></html></f:subview>
victormenegusso
veja como esta o código fonte pelo browser… as vezes o elemento que você quer não estar herdando apena a ID do form… logo nao daria para pegar apenas com document.getElementById(‘aForm:anInput’);
vc teria que fazer algo como…
coloque o ( prependId=“false” ) dentro do Form e utilize o document.getElementById(‘anInput’);
Schoker
eu vi o codigo fonte e as input’s estao com o id assim: conteudo:conteudo_lateral_direita:razao_social_adm
“conteudo” é uma div que eu carrega a div “conteudo_lateral_direita” que carrega esta pagina…
e eu puis isso no get element id e deu certo rs
victormenegusso
Schoker:
eu vi o codigo fonte e as input’s estao com o id assim: conteudo:conteudo_lateral_direita:razao_social_adm
“conteudo” é uma div que eu carrega a div “conteudo_lateral_direita” que carrega esta pagina…
e eu puis isso no get element id e deu certo rs
sim sim, isto acontece pois o JSF monta meio que uma arvore de IDs… logo os elementos filhos recebem a ID do elemento pai na sua id… ficando separado pelos “:” …
ai quando vc coloca o comando ( prependId=“false” ) o elemento pai não passa para seus filhos a sua ID
protonss
Schoker:
tem partes estranhas no codigo rsrs...mas nem esquenta que sao testes rsrs..
<%@pagecontentType="text/html"pageEncoding="ISO-8859-1"%><%@taglibprefix="f"uri="http://java.sun.com/jsf/core"%><%@taglibprefix="h"uri="http://java.sun.com/jsf/html"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><f:subviewid="conteudo_lateral_direita"><html><head><metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"/><scripttype="text/javascript">$(document).ready(function(){$('#cadastrar').button();$('#cadastrar').click(function(){varnome=document.getElementById('formulario:nome_adm').value;alert(nome);});$('#novo').button({icons:{primary:'ui-icon-document'}});$('#editar').button({icons:{primary:'ui-icon-pencil'}});$('#excluir').button({icons:{primary:'ui-icon-trash'}});$('#conteudo').css('height','880px');$('#novo').click(function(){varxml="<administradora>\n\ <codigo>0</codigo>\n\ <nome>heitor</nome>\n\ <razaoSocial>razao</razaoSocial>\n\ <cnpj>12345678912345</cnpj>\n\ <rua>rua</rua>\n\ <bairro>bairro</bairro>\n\ <complemento>comlemento</complemento>\n\ <numero>62</numero>\n\ <cep>13339520</cep>\n\ <cidade>indaiatuba</cidade>\n\ <uf>SP</uf>\n\ <telefone>30160786</telefone>\n\ <ddd>19</ddd>\n\ <email>[email removido]</email>\n\ <site>site.com.br</site>\n\ <nomeResponsavel>heitor</nomeResponsavel>\n\ <telefoneResponsavel>12345678</telefoneResponsavel>\n\ <dddTelefoneResponsavel>19</dddTelefoneResponsavel>\n\ <celularResponsavel>12345678</celularResponsavel>\n\ <dddCelularResponsavel>19</dddCelularResponsavel>\n\ <nextelResponsavel>[telefone removido]</nextelResponsavel>\n\ <emailResponsavel>[email removido]</emailResponsavel>\n\ <usuarioPainel>dadasdas</usuarioPainel>\n\ <senhaPainel>dsadas</senhaPainel>\n\ <ultimoAcesso>2005-12-13 17:26:58.772 CET</ultimoAcesso>\n\ <dataCadastro>2005-12-13 17:26:58.772 CET</dataCadastro>\n\ <status>false</status>\n\ </administradora>";$.post("Servlet",{action:"cadastrar",bean:"Administradora",param:xml});alert("aqui");});});</script></head><body><divid="titulo"><h:outputTextvalue="Listagem de Usuários"/></div><h:formid="formulario"><divid="formulario"><h3style="margin-top: 0px;"><h:outputTextvalue="Informações da administradora"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="nome_adm"value="Nome:"/><h:inputTextid="nome_adm"value=""size="82"maxlength="50"/><h:outputLabelfor="razao_social_adm"value="Razão Social:"/><h:inputTextid="razao_social_adm"value=""size="82"maxlength="50"/><h:outputLabelfor="cnpj_adm"value="CNPJ:"/><h:inputTextid="cnpj_adm"value=""size="15"maxlength="14"/><h:outputLabelfor="rua_adm"value="Rua:"/><h:inputTextid="rua_adm"value=""size="70"maxlength="50"/><h:outputLabelfor="bairro_adm"value="Bairro:"/><h:inputTextid="bairro_adm"value=""size="70"maxlength="50"/><h:outputLabelfor="complemento_adm"value="Complemento:"/><h:inputTextid="complemento_adm"value=""size="82"maxlength="100"/><h:outputLabelfor="numero_adm"value="Número:"/><h:inputTextid="numero_adm"value=""size="5"maxlength="6"/><h:outputLabelfor="cep_adm"value="CEP:"/><h:inputTextid="cep_adm"value=""size="8"maxlength="9"/><h:outputLabelfor="cidade_adm"value="Cidade:"/><h:inputTextid="cidade_adm"value=""size="40"maxlength="40"/><h:outputLabelfor="estado_adm"value="Estado:"/><h:selectOneMenuid="estado_adm"><f:selectItemsvalue="#{usuario.estados}"/></h:selectOneMenu><h:outputLabelfor="telefone_adm"value="Telefone:"/><h:inputTextid="telefone_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="email_adm"value="Email:"/><h:inputTextid="email_adm"value=""size="60"maxlength="80"/><h:outputLabelfor="site_adm"value="Site:"/><h:inputTextid="site_adm"value=""size="60"maxlength="80"/></h:panelGrid><br/><h3><h:outputTextvalue="Informações do responsável"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="nome_resp_adm"value="Nome:"/><h:inputTextid="nome_resp_adm"value=""size="82"maxlength="40"/><h:outputLabelfor="telefone_resp_adm"value="Telefone:"/><h:inputTextid="telefone_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="celular_resp_adm"value="Celular:"/><h:inputTextid="celular_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="nextel_resp_adm"value="Nextel:"/><h:inputTextid="nextel_resp_adm"value=""size="12"maxlength="20"/><h:outputLabelfor="email_resp_adm"value="Email:"/><h:inputTextid="email_resp_adm"value=""size="60"maxlength="80"/></h:panelGrid><br/><h3><h:outputTextvalue="Informações da conta de usuário"/></h3><h:panelGridcolumns="2"columnClasses="colunaAdm1, colunaAdm2"width="625"><h:outputLabelfor="usuario_adm"value="Usuário:"/><h:inputTextid="usuario_adm"value=""size="20"maxlength="40"/><h:outputLabelfor="senha_adm"value="Senha:"/><h:inputSecretid="senha_adm"value=""size="20"maxlength="40"/><h:outputLabelfor="confirmar_senha_adm"value="Confirmar senha:"/><h:inputSecretid="confirmar_senha_adm"value=""size="20"maxlength="40"/></h:panelGrid><br/><br/><aid="cadastrar"><h:outputTextvalue="Cadastrar"/></a></div></h:form></body></html></f:subview>
Amigo uma dica você pode usar jQuery para pegar os valores do campo da seguinte forma:
<< var nome = document.getElementById('formulario:nome_adm').value;