I'm having an issue with Ajax using a JQuery (to query MSSQL 2K8) to populate 2 text fields as you can see in the code below I have two PHP pages.
The main page that have a form with 2 text fields that need to be field with the selected result from the second page Ajax JQuery query.
I'm not being able to make the result selectable much less to populate the 2 fields.
I would like to populate the hidden field "id" with the value of "m.pessoas_id" and the field "find" with the value "m.nome" from the DB query.
Below the two pages code Any help will be appreciated.
Main Page
Now the page that run the JQuery query
AL Almeida
CIO
May all those that come behind us, find us faithful.
The main page that have a form with 2 text fields that need to be field with the selected result from the second page Ajax JQuery query.
I'm not being able to make the result selectable much less to populate the 2 fields.
I would like to populate the hidden field "id" with the value of "m.pessoas_id" and the field "find" with the value "m.nome" from the DB query.
Below the two pages code Any help will be appreciated.
Main Page
Code:
<?php
require_once'DbConnection.php';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="pt-br" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jQuery</title>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript">
$('document').ready(function(){
$('#loading').hide();
$('#find').click(function(){
$('#find').val('');
});
$('#find').keyup(function(){
$('#loading').ajaxStart(function(){
$('#target').hide();
$('#loading').show();
});
$('#loading').ajaxStop(function(){
$('#loading').hide();
});
$.post('buscaAjaxJQueryTest.php',
{busca: $('#find').val()},
function(data){
if ($('#find').val()!=''){
$('#target').show();
$('#target').empty().html(data);
}
else{
$('#target').empty();
}
}
);
});
});
</script>
</head>
<body>
<div id="main">
<div id="busca">
<form>
<fieldset>
<legend>Busca usando JQuery</legend>
<input name="id" id="id" type="hidden" value=""/>
<input name="find" id="find" type="text" value="Digite o Nome" size="50" />
<div id="loading"><img src="BarraCarregando.gif"> </div>
<div id="target"></div>
</fieldset>
</form>
</div> <!-- busca -->
</div> <!-- main -->
</body>
</html>
Code:
<?php
header("Content-Type: text/html; charset=ISO-8859-1",true);
require_once'DBConnection.php';
if (isset($_POST['busca'])){
$queryString = $_POST['busca'];
$sql = new contomssql();
$s=$sql->query("SELECT TOP 10 m.pessoas_id, m.nome FROM (SELECT DISTINCT p.pessoas_id , p.nome FROM tbl_Pessoas p where p.nome LIKE '$queryString%') m","");
$s1 = $sql->objects("",$s);
do {
echo '<ul>';
echo '<li>'.$s1->pessoas_id.' - '.$s1->nome.'</li>';
echo '</ul>';
} while($s1 = $sql->objects('',$s));
} else{
echo 'Error try again';
}
?>
AL Almeida
CIO
May all those that come behind us, find us faithful.