473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Populating dropdown box with filenames

132 100+
Hi all,

I have this code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript"> 
  4. var path = "C:\\Test\\Directory" 
  5.  
  6. function ShowFolderFileList() 
  7. var fso, f, fc, s, temp; 
  8. fso = new ActiveXObject("Scripting.FileSystemObject"); 
  9. f = fso.GetFolder(path); 
  10. fc = new Enumerator(f.files); 
  11. s = "";
  12. temp = "";
  13. for (; !fc.atEnd(); fc.moveNext()) 
  14.   { 
  15.   temp = fc.item();
  16.   document.getElementById('filelist').options[document.getElementById('filelist').options.length] = new Option (temp, temp); // First value is the TEXT of the option, the second is the VALUE of the option.
  17.   } 
  18. }
  19.  
  20. </script>  
  21.  
  22. </head>
  23. <body>
  24. <input type="button" onclick="ShowFolderFileList()" value="TEST">
  25. <select id="filelist">
  26.  
  27. </select>
  28.  
  29. </body>
  30. </html>
  31.  
Now this code works perfectly but it shows the entire pathname of the file.
So what I tried to do is to remove the path and just keep the filename. So I added into the loop just below temp = fc.item();

Expand|Select|Wrap|Line Numbers
  1.   s = temp.replace(/C:\\Test\\directory\\/g,"")
  2.  
And when I do this I get this error: This property or method is not supported by this object.

So the problem is that I'm referring to temp which is actually an object. And the replace function only works on strings. So my problem is that I don't know how to change it.

When I alert(temp) right after temp = fc.item(); I do get the complete path. So that's what's so weird to me.

Anyone with some thoughts?
Thanks,
Kenneth
Mar 6 '09 #1
4 7395
acoder
16,027 Expert Mod 8TB
I'm not sure what the exact type of item() would be, but perhaps you could try using the toString() method.
Mar 6 '09 #2
Dormilich
8,658 Expert Mod 8TB
you could either get the property of temp, that holds the string or use the temp.toString() method to convert the object to a string.
Mar 6 '09 #3
Cainnech
132 100+
The .toString() metod doesn't work. But after a while doing "research" on the net and experimenting I found out that the item() has a series of properties depending on what kind of object you are referring to.

In that view I found that what I was trying to do was not necessary because this is already a property of the item.

So the new code has become:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript"> 
  4. var path = "C:\\test\\directory" 
  5.  
  6. function ShowFolderFileList() 
  7.         var fso, f, fc, s, temp; 
  8.         fso = new ActiveXObject("Scripting.FileSystemObject"); 
  9.         f = fso.GetFolder(path); 
  10.         fc = new Enumerator(f.files); 
  11.         s = "";
  12.         temp = "";
  13.         for (; !fc.atEnd(); fc.moveNext()) 
  14. temp = fc.item();
  15. s = temp.name;
  16. document.getElementById('filelist').options[document.getElementById('filelist').options.length] = new Option (s, s);
  17. }; 
  18. }
  19.  
  20. </script>  
  21.  
  22. </head>
  23. <body>
  24. <input type="button" onclick="ShowFolderFileList()" value="TEST">
  25. <select id="filelist">
  26.  
  27. </select>
  28.  
  29. </body>
  30. </html>
  31.  
So the s = temp.name; shows me immediately the name of the file instead of the complete path.

Thanks for putting me in the right direction.
Mar 6 '09 #4
acoder
16,027 Expert Mod 8TB
Glad you managed to solve it. Here's a link to the Name property and a reference for completeness.
Mar 6 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
3
by: to_rgoyal | last post by:
Hi All, I am creating one web base application using ASP.net and C#. I am populating dropdown lists of my web pages using database. I am using this code: con = new...
1
by: Patrick.O.Ige | last post by:
Doing the simple DropDown List binding using the method NextResult() But its just not populating .. what am i missing Its populating the 3 DropDwonList but no Data? Private Sub...
4
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers...
1
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt"...
2
by: mamun | last post by:
Hi All, The problem is as follows: I have a table from where I am getting consultant's name and populating the dropdown list control. But I want to populate the default one which I got it as...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
2
by: Johnny BeGood | last post by:
Hi All, I need to populate a list box and/or a dropdown list on a form. I have all the bits and pieces together, all bar the code which takes the result of a query and creates a list box. Any...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.