Jump to content

DropDown list question


Charlatat

Recommended Posts

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

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

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

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

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

<!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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...