Salve a tutti,
io ho questa pagina php:
Il problema è che funziona la parte che cliccando aggiuge una nuova riga, creando l'array come sempre, ma la parte che dovrebbe fare l'autocompletamento non funziona...
Premetto che la parte dell'autocompletamento funziona perfettamente standalone ma integrata a questa non ne vuole sapere...
La pagine getclient è questa:
io ho questa pagina php:
PHP:
<?php
include('connect.php');
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>Creazione DdT</title>
<style type="text/css">
* { font-family:Arial; }
h2 { padding:0 0 5px 5px; }
h2 a { color: #224f99; }
a { color:#999; text-decoration: none; }
a:hover { color:#802727; }
p { padding:0 0 5px 0; }
input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
</style>
<script type="text/javascript" src="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 = '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['clientForm'];
eval(ajax.response);
}
function initFormEvents()
{
document.getElementById('clientID').onblur = getClientData;
document.getElementById('clientID').focus();
}
window.onload = initFormEvents;
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
$("#aggiungi").click(function() {
elem = $(".campo").first().clone();
elem.css("display", "block");
elem.appendTo("#campi");
});
$("#campi").on("click", ".remove", function() {
$(this).parent().remove();
});
$("#aggiungi").click();
});
</script>
<style type="text/css">
body { background-image: url(sfondo.jpg);
background-repeat: repeat-x;
font: Eras Medium ITC;
}
</style>
<style type="text/css">
#main {
width:820px;
height:600px;
position:absolute;
top:352px;
left:523px;
margin:-150px 0 0 -336px;
}
</style>
</head>
<body bgcolor="#f7b76b">
<p align="center">
<img src="images/logo.png" >
<form action="read_ddt.php" method="post" name="read">
<div id="main">
Operatore: <font color="#FF0000"><?php echo $_SESSION[user]; ?></font><br>
Data: <?php echo (date("d/m/Y"));?><br>
Ora: <?php echo (date("H:i"));?><br>
Barcode card:<font color="#FF0000"><?php echo $_SESSION[barcode]; ?></font><br><br>
<input type="button" onClick="window.open('puntifidelity.htm', 'Cerca card', 'width=690, height=700, resizable, status, scrollbars=1, location');"
value="Cerca card">
<p align="left"><a href="#" id="aggiungi">Aggiungi riga</a></p>
<div id="campi">
<p>
<div class="campo" style="display: none;">
<input name="clientID" id="clientID" size="5" maxlength="4">
<input type="text" placeholder="Descrizione" name="descrizione[]" id="descrizione">
<input type="text" placeholder="Quantità" name="quantita[]" id="quantita">
<input type="text" placeholder="Prezzo" name="prezzo[]" id="prezzo">
<br><a href="#" class="remove">Rimuovi riga</a></br>
</p>
</div>
</div>
<p>
<input name="read" type="submit" id="read" value="Inserisci">
</p>
</div>
</form>
</p>
</body>
</html>
Il problema è che funziona la parte che cliccando aggiuge una nuova riga, creando l'array come sempre, ma la parte che dovrebbe fare l'autocompletamento non funziona...
Premetto che la parte dell'autocompletamento funziona perfettamente standalone ma integrata a questa non ne vuole sapere...
La pagine getclient è questa:
PHP:
<?php
/* Replace the data in these two lines with data for your db connection */
$connection = mysql_connect("localhost","adminteclis","password");
mysql_select_db("my_adminteclis",$connection);
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.descrizione.value = '".$inf["firstname"]."';\n";
echo "formObj.quantita.value = '".$inf["lastname"]."';\n";
echo "formObj.prezzo.value = '".$inf["address"]."';\n";
}else{
echo "formObj.firstname.value = '';\n";
echo "formObj.lastname.value = '';\n";
echo "formObj.address.value = '';\n";
}
}
?>