Metto il codice:
Parte che richiede alla pagina getClient.php di cercare il prodotto
codice:
<script type="text/javascript">
var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById('descrizione[]').value;
if(clientId!=currentClientID){
currentClientID = clientId
ajax.requestFile = 'getClient.php?getClientId='+clientId; // Specifying which file to get
ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
}
function showClientData()
{
var formObj = document.forms['offerta'];
eval(ajax.response);
}
function initFormEvents()
{
document.getElementById('descrizione[]').onblur = getClientData;
document.getElementById('descrizione[]').focus();
}
window.onload = initFormEvents;
</script>
Pezzo del form (il form può essere di n righe tutte così)
codice:
<input size="15" type="text" id="codice[]" name="codice[]" disabled="disabled"><select name="descrizione[]" id="descrizione[]">
<option value="0">Selezionare un prodotto</option>
<option value="Prodotto1">Prodotto1</option>
Pagina getClient.php
codice:
if(isset($_GET['getClientId'])){
$res = mysql_query("select * from prodotti where descrizione='".$_GET['getClientId']."'") or die(mysql_error());
if($inf = mysql_fetch_array($res)){
echo "formObj.codice.value = '".$inf["cod"]."';\n";
echo "formObj.prezzo.value = '".$inf["prezzo_acquisto_standard"]."';\n";
}else{
echo "formObj.codice.value = '';\n";
echo "formObj.prezzo.value = '';\n";
}
}
Grazie!!