Charlatat Posted November 20, 2006 Share Posted November 20, 2006 I've successfully created a page that can pull data from a *.csv file, and can scroll thru the data via back/forth buttons. However, I need to know if its possible to automatically pull the data from the file, and populate a dropdown list instead? And if it is possible, what would the code look like? Thanks Link to comment Share on other sites More sharing options...
jlhaslip Posted November 20, 2006 Share Posted November 20, 2006 I don't have a code snippet handy, but open the file, read the data one line at a time and insert the data for the drop-down into an array. Use the array to populate the drop-down by looping through and adding the option tags. When I get my laptop back, later in the week, I have a snippet which does exactly that and I will post it up. (if I remember) In the meantime, perhaps someone else has a snippet??? Link to comment Share on other sites More sharing options...
Charlatat Posted November 22, 2006 Author Share Posted November 22, 2006 I don't have a code snippet handy, but open the file, read the data one line at a time and insert the data for the drop-down into an array. Use the array to populate the drop-down by looping through and adding the option tags. When I get my laptop back, later in the week, I have a snippet which does exactly that and I will post it up. (if I remember) In the meantime, perhaps someone else has a snippet???Anyone? Link to comment Share on other sites More sharing options...
aalbetski Posted November 22, 2006 Share Posted November 22, 2006 Show an example of your data. Link to comment Share on other sites More sharing options...
Charlatat Posted November 22, 2006 Author Share Posted November 22, 2006 Office WeblinkAnoka MN http://www.mapquest.com/directions/main.ad...z=55303&r=fArlington MN http://www.mapquest.com/directions/main.ad...z=55307&r=fAshland WI http://www.mapquest.com/directions/main.ad...z=54806&r=ffield1 = Office, field2 = Weblink Link to comment Share on other sites More sharing options...
aalbetski Posted November 22, 2006 Share Posted November 22, 2006 So, is this you're desired result?<select><option value="ttp://www.mapquest.com/directions/main.ad...z=55303&r=f">Anoka MN</option><option value="ttp://www.mapquest.com/directions/main.ad...z=55307&r=f">Arlington MN</option><option value="ttp://www.mapquest.com/directions/main.ad...z=54806&r=f">Ashland WI</option></select> Link to comment Share on other sites More sharing options...
Charlatat Posted November 22, 2006 Author Share Posted November 22, 2006 Well, yes and no.Those are the options I want presented in the dropdown list, yes. But, these entries and more are located in an external CSV file. I've been successful in pulling data from this file, when using buttons to navigate the rows. However, I need this info to be available in a dynamic dropdown list. Link to comment Share on other sites More sharing options...
aalbetski Posted November 22, 2006 Share Posted November 22, 2006 Thats where I was going, but first I want to understand what your expected result is before I propose a solution.Now, show the code that you use to read the CSV file Link to comment Share on other sites More sharing options...
Charlatat Posted November 22, 2006 Author Share Posted November 22, 2006 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>MapQuest Directions from GoldMine</TITLE></HEAD><script FOR=tdcLinks EVENT=ondatasetchanged> // Once the recordset is available, set the web page URL to the last record in the data set WEBLINK=tdcLinks.recordset.fields('Weblink');</SCRIPT><script FOR=btnLink EVENT=onclick> window.open(WEBLINK);</SCRIPT><div style="display:none"><OBJECT classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" ID=tdcLinks HEIGHT=0 WIDTH=0> <PARAM NAME="DataURL" VALUE="OfficeLoc.csv"> <PARAM NAME="UseHeader" VALUE="True"></OBJECT></div><H2>Select an Office:</H2><INPUT ID=cmdNavFirst TYPE=BUTTON VALUE="<<" onclick="tdcLinks.recordset.MoveFirst()"><INPUT ID=cmdNavPrev TYPE=BUTTON VALUE="<" STYLE="width:20px" onclick="tdcLinks.recordset.MovePrevious(); if (tdcLinks.recordset.BOF)tdcLinks.recordset.MoveFirst();"><INPUT ID=cmdNavNext TYPE=BUTTON VALUE=">" STYLE="width:20px" onclick="tdcLinks.recordset.MoveNext(); if(tdcLinks.recordset.EOF)tdcLinks.recordset.MoveLast();"><INPUT ID=cmdNavLast TYPE=BUTTON VALUE=">>" onclick="tdcLinks.recordset.MoveLast()"><BR><BR><BR>Click this button to get directions to <TAB><BUTTON ID="btnLink" DATASRC="#tdcLinks" DATAFLD="Office"></BUTTON></HTML> Link to comment Share on other sites More sharing options...
aalbetski Posted November 22, 2006 Share Posted November 22, 2006 you're close. try something along these lines: var html = ""html += "<select id='placeholder'>"if(!tdcLinks.recordset.bof) { tdcLinks.recordset.MoveFirst() while(!tdcLinks.recordset.eof) { html += '<option value="' + dcLinks.recordset.fields(id).value + '">' + dcLinks.recordset.fields(val).value + '</option>' tdcLinks.recordset.MoveNext() } } tdcLinks.recordset.close()html += "</select>" It probably needs to be cleaned up. just send the html string to the outerHTML of an existing <select>ex:<select id="placeholder" />document.getElementById('placeholder').outerHTML = html Link to comment Share on other sites More sharing options...
Charlatat Posted November 22, 2006 Author Share Posted November 22, 2006 Ok, I'll try to struggle with it, since I'm only passingly familiar with HTML. I'm trying to eliminate the buttons and any SCRIPT out of it entirely. So that when they select an item from the dropdown list, it goes immediately to the weblink location. Is that possible? Link to comment Share on other sites More sharing options...
aalbetski Posted November 22, 2006 Share Posted November 22, 2006 here is a complete example (will only work in IE, but from what I can tell, thats what you're using). Because this is using client-side script you will have difficulity in publishing it with all the blocks there are now for objects and such, you may want to consider ASP for that reason, but nonetheless, this is a complete, working example:The CSV file I used (called tdcLinks.csv) "Office","URL""Anoka MN","http://www.mapquest.com/directions/main.ad...z=55303&r=f""Arlington MN","http://www.mapquest.com/directions/main.ad...z=55307&r=f""Ashland WI","http://www.mapquest.com/directions/main.ad...z=54806&r=f" The HTML <html><script for="placeholder" event="onclick"> window.open(window.event.srcElement.value);</script><body onLoad="LoadCSV()"> <OBJECT classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" ID=tdcLinks HEIGHT=0 WIDTH=0> <PARAM NAME="DataURL" VALUE="tdcLinks.csv"> <PARAM NAME="UseHeader" VALUE="True"> </OBJECT> <select id="placeholder"/></body><script>function LoadCSV(){ var html = "" html += "<select id='placeholder'>" tdcLinks.recordset.MoveFirst() while(!tdcLinks.recordset.eof) { html += '<option value="' + tdcLinks.recordset.fields('URL').value + '">' + tdcLinks.recordset.fields('Office').value + '</option>' tdcLinks.recordset.MoveNext() } html += "</select>" document.getElementById("placeholder").outerHTML = html}</script></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now