hello frnds,
I have a code snippet where auto suggest dropdown will come in basis of text box value entered by the user.
<?php
$response="";
$i=0;
$con=mysql_connect("localhost","root","root");
mysql_select_db("autosuggest",$con)or die(mysql_error());
print "<script>var jarray = Array();</script>";
$q=mysql_query("select * from suggestion");
$n=mysql_num_rows($q);
while($r=mysql_fetch_array($q))
{
$response=$r['suggest'];
print "<script> jarray[".$i."]='".$response."'</script>";
$i++;
}
?>
this code will retrive the suggestion inventory from the database.
and here is the code of javascript that create a suggestion array in helping the auto suggestion
<script type="text/javascript">
function StateSuggestions() {
this. states = [
"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut",
"Delaware", "Florida", "Georgia", "Hawaii",
"Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana",
"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
"Mississippi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Mexico", "New York",
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming"
];
}
/**
* Request suggestions for the given autosuggest control.
* @scope protected
* @param oAutoSuggestControl The autosuggest control to provide suggestions for.
*/
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
bTypeAhead /*:boolean*/) {
var aSuggestions = [];
var sTextboxValue = oAutoSuggestControl.textbox.value;
if (sTextboxValue.length > 0){
//search for matching states
for (var i=0; i < this.states.length; i++) {
if (this.states[i].indexOf(sTextboxValue) == 0) {
aSuggestions.push(this.states[i]);
}
}
}
//provide suggestions to the control
oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
window.onload = function () {
var oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new StateSuggestions());
}
</script>
</head>
<body>
<p><input type="text" id="txt1" /></p>
</body>
</html>
the problem is that the list in the StateSuggestions() function is static so i try to make an array named
jarray which hold the values of database through php.The main problem is i dont able to integrate this
this. states array with the values of jarray.Plz any one tell me what is the problem i am facing ???
plz i dont get anything....
i am sending the actual files also...
Thanks.