retrieve a parameter from script (asp)

hey,

i have a search box, when i search, i see the results, when i click on it, i need only to retrieve the parameter "id",

the results are: firstname, lastname and id

how can i do that, idea's?

thx


(this is de loaded code:

<script>
      $(function() {
            var data = [

                       {label: "Bourins step", category: "29" },{label: "de Quirini Guibert", category: "28" },{label: "Defever Simone", category: "21" },{label: "degreve antéon", category: "24" },{label: "delfosse jan", category: "79" },{label: "delhez kristof", category: "78" },{label: "Dereumaux Catherine", category: "26" },{label: "devos jan", category: "82" },{label: "ellen verstraete", category: "86" },{label: "Gonsalez Jeremy", category: "22" },{label: "jan Simon", category: "74" },{label: "Jockir Jeremy", category: "30" },{label: "kkkkk ", category: "80" },{label: "Michiels Mireille", category: "25" },{label: "Renier Geraldine", category: "23" },{label: "slaets veronique", category: "87" },{label: "timmer anne", category: "85" },{label: "timmer anne", category: "84" },{label: "timmer anne", category: "83" },{label: "vermeire alain", category: "81" },{label: "verstrate ellen", category: "31" },
                  
            
            ];            

            
            $( "#search" ).catcomplete({
                  delay: 0,
                  source: data
            });
      });
      </script>
)

i only want the id of the choosen person...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
	<link rel="stylesheet" href="jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css">
	<script src="jquery-ui-1.8.16.custom/development-bundle/jquery-1.6.2.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.autocomplete.js"></script>
	<link rel="stylesheet" href="jquery-ui-1.8.16.custom/development-bundle/demos/demos.css">
	<style>
	.ui-autocomplete-category {
		font-weight: bold;
		padding: .2em .4em;
		margin: .8em 0 .2em;
		line-height: 1.5;
	}
	</style>

</head>

<body>


<%
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Server.MapPath("database.accdb")


%>




	<script>
	$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";
			$.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
				}
				self._renderItem( ul, item );
			});
		}
	});
	</script>
	<%
		Set rst2= Server.CreateObject("ADODB.Recordset")
	strsql2 = "SELECT * from contacts order	by lastname"
	rst2.Open strsql2,adoCon,,3


	%>
	<script>
	$(function() {
		var data = [

                       <%  
                         if not rst2.eof or not rst2.bof then ' make sure there is data
                              do until rst2.eof 'start loop
                              response.write "{label: """&rst2("lastname") &" "&rst2("firstname") &""", category: """&rst2("idcontact") &""" }," 'sample data { label: "annhhx10", category: "Products" }
                              rst2.movenext
                              loop
						end if
                        %>
			
		
		];		

		
		$( "#search" ).catcomplete({
			delay: 0,
			source: data
		});
	});
	</script>


<input type="text" id="search" />
</body>

</html>

Open in new window

fedkrisAsked:
Who is Participating?
 
Robert SchuttSoftware EngineerCommented:
Hi, I thought I'd give it a shot:

I have tested it without a database, just one line of data.

line 67 change to:

                              response.write "{label: """ & rst2("lastname") & " " & rst2("firstname") & """, category: ""people"", idcontact: " & rst2("idcontact") & " },"

Open in new window


so this is untested but should work if that is the field name ("idcontact") in the database.

What it does: have 1 category for all lines ("people") and add a custom value that will be ignored by the existing code for the autocomplete functionality.


Then change line 77-80 to:

		$( "#search" ).catcomplete({
			delay: 0,
			source: data,
			select: function(event, ui) {
				$("#idcontact").val( !ui.item ? "N/A" : ui.item.idcontact);
			}
		});

Open in new window


So this adds a function that copies the id from the person that was selected to a separate input field. You can make that field hidden but for now I've added it visible, for example before the existing input field:

<input type="text" id="idcontact" />

Open in new window


Now for completeness here is the code I used for testing, with the database calls commented out, just for reference:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
	<link rel="stylesheet" href="jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css">
	<script src="jquery-ui-1.8.16.custom/development-bundle/jquery-1.6.2.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.autocomplete.js"></script>
	<link rel="stylesheet" href="jquery-ui-1.8.16.custom/development-bundle/demos/demos.css">
	<style>
	.ui-autocomplete-category {
		font-weight: bold;
		padding: .2em .4em;
		margin: .8em 0 .2em;
		line-height: 1.5;
	}
	</style>

</head>

<body>


<%
'Set adoCon = Server.CreateObject("ADODB.Connection")
'adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Server.MapPath("database.accdb")


%>




	<script>
	$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";
			$.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
				}
				self._renderItem( ul, item );
			});
		}
	});
	</script>
	<%
	'	Set rst2= Server.CreateObject("ADODB.Recordset")
	'strsql2 = "SELECT * from contacts order	by lastname"
	'rst2.Open strsql2,adoCon,,3


	%>
	<script>
	$(function() {
		var data = [

                       <%  
                         'if not rst2.eof or not rst2.bof then ' make sure there is data
                              'do until rst2.eof 'start loop
                              'response.write "{label: """ & rst2("lastname") & " " & rst2("firstname") & """, category: ""people"", idcontact: " & rst2("idcontact") & " },"
			      'sample data { label: "annhhx10", category: "Products" }
			      response.write "{ label: ""annhhx10"", category: ""people"", idcontact: 125 }"
                              'rst2.movenext
                              'loop
				'		end if
                        %>
			
		
		];		

		
		$( "#search" ).catcomplete({
			delay: 0,
			source: data,
			select: function(event, ui) {
				$("#idcontact").val( !ui.item ? "N/A" : ui.item.idcontact);
			}
		});
	});
	</script>


<input type="text" id="idcontact" /> &lt;-- make this hidden
<br />
<br />
<input type="text" id="search" />
</body>

</html> 

Open in new window

0
 
fedkrisAuthor Commented:
thx for all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.