logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-29-2010, 10:32 PM   #1
gavimobile
gavimobile's Avatar
 
Join Date: Mar 2007
Posts: 187
Default getting annother value

hi folks,
my javascript is poor, could someone give me a hand here?

i have a function which sends the value of a field to a php page and returns an autocomplete result list based on the keyes entered in the field. however i have alot of rows in my database and i would like to improve the response time by adding an additional field.

This is the javascript function i need to edit (just not sure how).
HTML Code:
<script type="text/javascript">
 function lookup(inputString) {
  if(inputString.length == 0) {
   // Hide the suggestion box.
   $('#suggestions').hide();
  } else {
   $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
    if(data.length >0) {
     $('#suggestions').show();
     $('#autoSuggestionsList').html(data);
    }
   });
  }
 } // lookup
 function fill(thisValue) {
  $('#inputString').val(thisValue);
  setTimeout("$('#suggestions').hide();", 200);
 }
</script>
inputString is the id of the autocomplete field, this is how javascript is posting the entered keys to the rpc.php file which allows the databse query to list results. i created a new field called city and i edited the php query. i want javascript to make sure city will be selected before so there will be less street names in the results which will allow the whole process to work faster.

do i need to create a new function? can i apply this to the same function?

here is the php file (rpc.php)
PHP Code:
<?php require_once("Connections/connect.php"); ?>
<?php
 
if(isset($_POST['queryString'])) {
  
$city trim($_POST['city']);
  
$trim trim($_POST['queryString']);
  
$queryString mysql_real_escape_string($trim);
  
$cityname mysql_real_escape_string($city);
  if(
strlen($queryString) >0) {
   
mysql_select_db($database_connect$connect);
   
$sql "SELECT * FROM table WHERE city = '$city' AND street LIKE '%$queryString%' LIMIT 5";
   
$result mysql_query($sql$connect) or die(mysql_error());
   while(
$row mysql_fetch_array($result)){
    echo 
'<li onClick="fill(\''.$row['street'].'\');">'.$row['street'].'</li>';
   }
  }
 }
?>
here is a more detailed post
HTML Code:
<html>
<head>
<script src="js/jquery-1.2.6.js" type="text/javascript"></script>
<script src="js/ui.core.js" type="text/javascript"></script>
<script src="js/ui.tabs.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css"href="css/flora.tabs.css" />
<link rel="stylesheet" type="text/css" href="css/autocomplete.css" />
<script type="text/javascript">
 function lookup(inputString) {
  if(inputString.length == 0) {
   // Hide the suggestion box.
   $('#suggestions').hide();
  } else {
   $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
    if(data.length >0) {
     $('#suggestions').show();
     $('#autoSuggestionsList').html(data);
    }
   });
  }
 } // lookup
 function fill(thisValue) {
  $('#inputString').val(thisValue);
  setTimeout("$('#suggestions').hide();", 200);
 }
</script>
</head>
<body>
<form method="post" name="form1" action="">
<select name="city" id="city" >
<options value="">Select City</option>
<options value="city">cityname</option>
</select>
<input type="text" name="address" id="inputString" onblur="fill();" onkeyup="lookup(this.value);" value="" size="32">
<div class="suggestionsBox" id="suggestions" style="display: none;">
      <div class="suggestionList" id="autoSuggestionsList">&nbsp;</div>
</div>
</form>
</body>
</html>
hope i was clear? please ask me if i wasnt.

tia
gavriel
__________________
there are many technicians today, but theres only 1 motek! motekpc.com
gavimobile is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:45 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com