Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed with Ajax using JQuery to return 2 values to 2 form fields

Status
Not open for further replies.

aalmeida

MIS
Aug 31, 2000
468
US
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
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>
Now the page that run the JQuery query

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.
 
since you're using jquery why not ask in the jquery forum?

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top