Jump to content


Photo

Php - Ajax - Combox Autocompletar


  • Faça o login para participar
Nenhuma resposta neste tópico

#1 jg7

jg7

    Novato no fórum

  • Usuários
  • 3 posts
  • Sexo:Masculino

Posted 02/04/2012, 15:33

Salve ai rapaziada, seguinte

eu como iniciante to tentando duplicar o seguinte codigo:


<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
if(clientId.length==4 && clientId!=currentClientID){
currentClientID = clientId
ajax.requestFile = 'edicao.php?getClientId='+clientId;
ajax.onCompletion = showClientData;
ajax.runAJAX();
}

}

function showClientData()
{
var formObj = document.forms['clientForm'];
eval(ajax.response);
}


function initFormEvents()
{
document.getElementById('clientID').onblur = getClientData;
}


window.onload = initFormEvents;
</script>



<div>
<form name="clientForm" action="" method="post">
<select name="clientID" id="clientID">
<option value"Número da p****">Número da p****</option>
<?php

$result = mysql_query("select * from ajax_client");

while($row = mysql_fetch_array($result) ){
echo "<option value='".$row['clientID']."'>".$row['clientID']."</option>";

}

?>
</select>
<input name="firstname" id="firstname" size="20" maxlength="255">
<input name="lastname" id="lastname" size="20" maxlength="255">
<input name="address" id="address" size="20" maxlength="255">
<input name="zipCode" id="zipCode" size="4" maxlength="5">
<input name="city" id="city" size="20" maxlength="255">
<input name="country" id="country" size="20" maxlength="255">
</form>
</div>








edicao.php seria assim:





if(isset($_GET['getClientId'])){
$res = mysql_query("select * from ajax_client where clientID='".$_GET['getClientId']."'") or die(mysql_error());
if($inf = mysql_fetch_array($res)){
echo "formObj.firstname.value = '".$inf["firstname"]."';\n";
echo "formObj.lastname.value = '".$inf["lastname"]."';\n";
echo "formObj.address.value = '".$inf["address"]."';\n";
echo "formObj.zipCode.value = '".$inf["zipCode"]."';\n";
echo "formObj.city.value = '".$inf["city"]."';\n";
echo "formObj.country.value = '".$inf["country"]."';\n";

}else{
echo "formObj.firstname.value = '';\n";
echo "formObj.lastname.value = '';\n";
echo "formObj.address.value = '';\n";
echo "formObj.zipCode.value = '';\n";
echo "formObj.city.value = '';\n";
echo "formObj.country.value = '';\n";
}
}




O que eu queria fazer era duplicar o codigo, tipo assim queria fazer um novo form puxando dados de outra parte do Banco de Dados, isso tudo na mesma pagina.... Exemplo:


<div>
<form name="clientForm" action="" method="post">
<select name="clientID" id="clientID">
<option value"Número da p****">Número da p****</option>
<?php

$result = mysql_query("select * from ajax_client");

while($row = mysql_fetch_array($result) ){
echo "<option value='".$row['clientID']."'>".$row['clientID']."</option>";

}

?>
</select>
<input name="firstname" id="firstname" size="20" maxlength="255">
<input name="lastname" id="lastname" size="20" maxlength="255">
<input name="address" id="address" size="20" maxlength="255">
<input name="zipCode" id="zipCode" size="4" maxlength="5">
<input name="city" id="city" size="20" maxlength="255">
<input name="country" id="country" size="20" maxlength="255">
</form>
</div>
<div>
<form name="senhaForm" action="" method="post">
<select name="senhaID" id="senhaID">
<option value"Número da p****">Número da p****</option>
<?php

$result = mysql_query("select * from outrabd");

while($row = mysql_fetch_array($result) ){
echo "<option value='".$row['senhaID']."'>".$row['senhaID']."</option>";

}

?>
</select>
<input name="usuario" id="usuario" size="20" maxlength="255">
<input name="senha" id="senha" size="20" maxlength="255">
</form>
</div>





Alguem tem uma alternativa?? a duvida é na montagem ali do Javascript.. num to conseguindo




1 user(s) are reading this topic

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

IPB Skin By Virteq