Link to home
Create AccountLog in
Avatar of stkoontz
stkoontzFlag for United States of America

asked on

Pass variable after live search

I found a tutorial to create  a live search option using jquery, javascript, and PHP which I've managed to get to work.  But I'm having trouble figuring out how to pass the users selection to another page.  The page I'm working on is here:  http://registration.cenational.org/admin/search.html.  When you type any letter, you'll get a list of names.  I want the user to be able to choose a name, then have the associated registrant ID be passed to another page.  

Can anyone help me get started with what code to use to have the function pass the chosen name to another page for processing?

Thanks,

Steve

The code is below

HTML page

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
	function getfname(value) {
        $.post("searchfname.php", {partialfname:value},function(data) {
        $("#results").html(data);
        });
    }
	</script>

<title>Untitled Document</title>
</head>

<body>

<form id="form1" name="form1" >
  <input type="text" onkeyup="getfname(this.value)"/>
  <input type="submit" name="button" id="button" value="Submit" />
</form>
<br />
<div id="results"></div>
</body>

Open in new window


PHP page
<?php

require_once('dbconxxxxx');


$var_partialfname=$_POST['partialfname'];

$fnameSearch = "SELECT id_registrant, fname FROM registrants WHERE fname LIKE '%" . $var_partialfname . "%'";

$rsfnameSearch = mysqli_query($link, $fnameSearch);

	while($row_rsfnameSearch = mysqli_fetch_array($rsfnameSearch)){
		
	echo "<div> First name " . $row_rsfnameSearch['fname'] . "</div>";
	}

mysqli_free_result($rsfnameSearch);

?>

Open in new window

Avatar of Gary
Gary
Flag of Ireland image

Place the <div id="results"></div> inside your form
In your ajax page add a radio to your echo (so they can make a selection) with a value of the id and a relevant name like registrant
SOLUTION
Avatar of Adam
Adam
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of stkoontz

ASKER

I'm making progress thanks to both of you.

The post is now going to the next page.  I just need to have the user be able to choose a selection instead of typing the text out completely.  I also need to have a user ID passed to the next page instead of the name that is typed.

Can you explain this more?  I don't understand how to add a radio to the echo.

"In your ajax page add a radio to your echo (so they can make a selection) with a value of the id and a relevant name like registrant"

The code is here...

echo "<div> First name " . $row_rsLnameSearch['fname'] . "</div>";


Thanks again,

Steve
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks for the help from both of you.  I'm well on my way.

Steve