Solved

help in jquery

Posted on 2009-04-02
1
304 Views
Last Modified: 2012-08-14
Hi am using autocomplete....
what i want is to populate 2 diferent sets of auto values based on the option button selection

what happens is when i choose the first option values are loaded properly but when i switch to 2 option values corresponding to 2 option are not loaded...values relating to first option only pops up...only when i refresh the page the other option value gets loaded....

values does not change based on option button change..but they change each time the page is refreshed.
<head>
<script type="text/javascript" src="jquery-autocomplete/lib/jquery.js"></script>  
<script type="text/javascript" src="jquery-autocomplete/jquery.autocomplete.js"></script>  
<script type="text/javascript" src="jquery-autocomplete/searchdata.php"></script>   
<link rel="stylesheet" type="text/css" href="jquery-autocomplete/jquery.autocomplete.css" />  
 
<script type="text/javascript">  
$(document).ready(function() { 
if(document.test.test1[0].checked)
 {
  
  $("#cse_search").autocomplete(searchdata2); 
  }
  if(document.test.test1[1].checked)
 {
 $("#cse_search").autocomplete(searchdata1);  
}
});  
</script>
</head>
<center>
<body onLoad="showClock()">
<form name='test' method='POST' action='<? $_SERVER['PHP_SELF'] ?>'>
 
 
<!-- start here Test Listing table -->
<div class="b2">
<fieldset>
<legend>&nbsp;<b>Test Listing&nbsp;</b></legend>
<table 	 cellspacing="2" cellpadding="2" border="0">
<tr>
 
<!-- start here Radio button table -->
 <td>
<table width="350"  height="55" border="0	" cellpadding="0" cellspacing="1" align="center"   >
 <tr>
<td><input type="radio" name="test1"></td><td>Testing</td>
<td><input type="radio" name="test1"></td><td>Profile</td>
<td><input type="radio" name="testing"></td><td>Master Profile</td>
 </tr>
 <tr>
 <td colspan="9"><input type="text" id="cse_search" name="q" size="31" /></td>
</tr>
</table>
 
...........................
searchdata.php
.............................
 
<?php  
    /* This script parses the Popular Queries feed from Google's CSE product and outputs 
       the recent queries in a JavaScript array for use with the jQuery Autocomplete plugin. */  
    // There may be some search queries you want to include in the autocomplete box  
    // that aren't necessarily popular searches and therefore don't show up in your   
    // Google CSE feed.  You can add those terms to this array to ensure they show up.  
    // You will want to make sure you enter the terms in lowercase.
	
	$server="localhost";
	$user="root";
	$password="";
	$database="lab";
	
	
	mysql_connect($server,$user,$password) or
	die("Unable to connect to the localhost");
	mysql_select_db($database) or 
	die("Database 'Products' doesn't exist!");
	
	$table="doctor";
	$query="select d_name from $table";
	$result=mysql_query($query);
	//$data=mysql_fetch_array($result);
	$num_rows = mysql_num_rows($result);
	
	
	
	
	// Load the Popular Queries RSS Feed from Google's CSE using SimpleXML  
     // The URL is available by clicking "Statistics" from inside your CSE control panel.  
   
    while($data1=mysql_fetch_array($result))
	 {
	 $data[]=$data1['d_name'];
	 }
	  
	
     // Format the data for JavaScript output. 
 
		sort($data); //alphabetize the array  
     foreach($data as $search_term) 
	 { 
	 $js_data[] ="\"" . $search_term . "\""; 
	 }     
     
    // Let's inform the browser that we're sending JavaScript.  
     //header("Content-type: text/javascript\n\n");  
      
     // Next we'll escape from PHP and create a JavaScript array. Inside the array, we'll return t 
    // PHP and use implode() to return a comma-separated string of all the data inside $js_data.  
 ?>  
 var searchdata1 = [<?php echo implode($js_data, ", "); ?>];  
 
<? 
 $table1="test_list";
	$query1="select tst_code from $table1";
	$result1=mysql_query($query1);
	//$data=mysql_fetch_array($result);
	$num_rows1 = mysql_num_rows($result1);
	
	
	
	
	// Load the Popular Queries RSS Feed from Google's CSE using SimpleXML  
     // The URL is available by clicking "Statistics" from inside your CSE control panel.  
   
    while($data2=mysql_fetch_array($result1))
	 {
	 $dat[]=$data2['tst_code'];
	 }
	  
	
     // Format the data for JavaScript output. 
 
		sort($dat); //alphabetize the array  
     foreach($dat as $search_trm) 
	 { 
	 $js_dat[] ="\"" . $search_trm . "\""; 
	 }     
     
    // Let's inform the browser that we're sending JavaScript.  
     //header("Content-type: text/javascript\n\n");  
      
     // Next we'll escape from PHP and create a JavaScript array. Inside the array, we'll return t 
    // PHP and use implode() to return a comma-separated string of all the data inside $js_data.  
 ?>  
 var searchdata2 = [<?php echo implode($js_dat, ", "); ?>];

Open in new window

0
Comment
Question by:whspider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
davidsperling earned 500 total points
ID: 24049157
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question