Jump to content


Photo

Pesquisar Nomes Com Campos Iguais


  • Faça o login para participar
1 reply to this topic

#1 *Michelle*

*Michelle*

    Novato no fórum

  • Usuários
  • 18 posts
  • Sexo:Não informado

Posted 09/06/2009, 16:24

Olá povo,

Estou usando o Ajax para exibir a descrição e o preço de uma peça cadastrada no banco atraves do codigo da peça.
Consegui fazer funcionar em um campo, mas o problema é que tenho uma tabela dinâmica e vários campos com o mesmo nome e o Ajax só tá funcionando uma vez, só na primeira linha....como posso fazer para diferenciar os campos? Sem mudar o nome do campo tem como??... Porque com o nome do campo que consigo fazer o vector para salvar no BD.

Página JSP (Principal):
<legend>Lançamento de Peças</legend>

	  <table id="tabelaP" border="0" align="left">
		<tr>
		<td width="5"><b>Cod.:</b></td>
		 <td width="10"><input type="text" name="txt_codpeca" id="txt_codpeca" maxlength="10" style="TEXT-TRANSFORM: uppercase;" size="7" onBlur="updateDadosP()"/></td>

		 <td width="260"><input type="text" name="txt_descpeca" id="txt_descpeca" maxlength="45" style="TEXT-TRANSFORM: uppercase;" size="37" readonly/></td>
		 
		  <td width="100"><b> Preço:</b> 
		   <input type="text" name="txt_precopeca" id="txt_precopeca" maxlength="8" size="5" value="0.00" readonly onBlur="subtotal()"/></td>
		 
		 <td width="100"><b> Quant.:</b> 
		   <input type="text" name="txt_quantpeca" id="txt_quantpeca" maxlength="8" size="5" value="0" onBlur="subtotal()"/></td>
 
		  <td width="90"><b> Total:</b> 
		   <input type="text" name="txt_subtotalp" id="txt_subtotalp" maxlength="8" size="5" value="0.00" readonly/></td>
			 
		 <td width="35"><button value="ADD" onclick="adicionarLinhaPeca();"><img height="18" width="20" alt="Incluir" src="images/incluir.gif" align="top"></button></td>
		 <td><button value="listart" onclick="deleteRowPeca()"><img height="18" width="20" src="images/excluir.gif" alt="Excluir Linha" align="absmiddle"/></button></td>
	</tr>

	  <tr>
		<td width="5"><b>Cod.:</b></td>
		 <td width="10"><input type="text" name="txt_codpeca" id="txt_codpeca" maxlength="10" style="TEXT-TRANSFORM: uppercase;" size="7" onBlur="updateDadosP()"/></td>

		 <td width="260"><input type="text" name="txt_descpeca" id="txt_descpeca" maxlength="45" style="TEXT-TRANSFORM: uppercase;" size="37" readonly/></td>
		 
		  <td width="100"><b> Preço:</b> 
		   <input type="text" name="txt_precopeca" id="txt_precopeca" maxlength="8" size="5" value="0.00" readonly onBlur="subtotal()"/></td>
		 
		 <td width="100"><b> Quant.:</b> 
		   <input type="text" name="txt_quantpeca" id="txt_quantpeca" maxlength="8" size="5" value="0" onBlur="subtotal()"/></td>
 
		  <td width="90"><b> Total:</b> 
		   <input type="text" name="txt_subtotalp" id="txt_subtotalp" maxlength="8" size="5" value="0.00" readonly/></td>
	</tr>
 </table>
 </fieldset>

Ajax.js
var url = "load_peca.jsp?txt_codpeca="; // The server-side script
var http = getHTTPObject(); // We create the XMLHTTPRequest Object

function handleHttpResponse() {
	if (http.readyState == 4) {
		if (http.status == 200) {
				  
			results = http.responseText.split(";");
			document.getElementById('txt_descpeca').value = results[0];
			document.getElementById('txt_precopeca').value = results[1];
		} else {
			alert ( "Peça Não Existe!" );
		}
	}	
}

function updateDadosP() {
	
	var codigoValue = document.getElementById("txt_codpeca").value;
http.open("GET", url + escape(codigoValue), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}

function getHTTPObject() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} return xmlhttp;
}

Load_peca.jsp
<%
 String codigo =request.getParameter("txt_codpeca");

 if (codigo != null){
	
		Peca peca = new DaoPeca().consultarPeca(codigo);

		out.print(""+peca.getDescricao()+";");
		out.print(""+Float.toString(peca.getPreco())+"");
 }
 else {
		//nothing to show
		response.setStatus(HttpServletResponse.SC_NO_CONTENT);
	}
%>

Alguém ajuda, por favor.

Obrigada,
Michelle

#2 Édipo Costa Rebouças

Édipo Costa Rebouças

    Veterano

  • Ex-Admins
  • 1079 posts
  • Sexo:Masculino
  • Localidade:Brasil - São Paulo

Posted 31/07/2009, 12:50

pelo id, você pode usar o mesmo name, mas o id é unico, e pode ser diferente do name.

Edição feita por: Édipo Costa Rebouças, 31/07/2009, 12:50.





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq