Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Dynamic Content with a Javascript

Status
Not open for further replies.

laural4705

Programmer
Joined
Mar 28, 2005
Messages
2
Location
US
I am new to javascript - I found the perfect script and need to tweak just a bit: it is an autosuggest script that gives the next word based on the last letter typed. It works fine, no errors. The list that it uses for suggestions is about 600 entries long (so far) - I would like to automatically generate the list from my database (Filemaker) - right now it is manually exported and statically placed in the page. Could anyone share with me how I would go about getting the dynamic content in the page? I am familiar with PHP and thought maybe I could use some sort of include or pointer file? I just don't know... Here is the code, thanks for helping :)


/**
* Provides suggestions for usernames.
* @class
* @scope public
*/
function StateSuggestions() {
this.states = [

"albert",
"bob",
"carol",
"cathy",
"melissa",
}

/**
* Request suggestions for the given autosuggest control.
* @scope protected
* @param oAutoSuggestControl The autosuggest control to provide suggestions for.
*/
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/) {
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.indexOf(sTextboxValue) == 0) {
aSuggestions.push(this.states);
}
}
}

//provide suggestions to the control
oAutoSuggestControl.autosuggest(aSuggestions);
};
 
This really becomes a PHP question if that is the server-side language you will use. You want to connect to your database, retrieve all the values and then write them out as a javascript array. You basically need to build a string containing the javascript script tags and the statements to create and populate the array then write that statement to the page from your PHP code. Most of your code above could stay on the page, only the portion that sets the array would need to be dynamic. But that will have to be server-side code such as PHP or ASP so that you can get the values from the database.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top