473,659 Members | 3,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript code to get FileName from File Inputbox

6 New Member
Alright, I'm very new to JavaScript but I'm fair with PHP.
I'm working on an uploader script and what I'm trying to do is take the file name from the file input box.

I looked at string manipulation in terms of using indexOf, substr, substring, etc... and I can't figure it out for the life of me!

Here is what I'm trying to do:

Example:
I select the file:
C:\Documents and Settings\BSPROG S\Desktop\DeVry \Previous work\BIS 440\ESSS_Case_S tudy.zip

I want to use the document.write command to write:
ESSS_Case_Study .zip

I've looked through my "JavaScript : The Definitive Guide" book from O'Reilly but luck.

Thanks for your help.

Steven
Jan 15 '07 #1
2 3947
vishnuvarthan
5 New Member
First, you split the string into string array using '\' and get its array length. Then get the penultimate string value.... Hope it works....Find below the example code..

var strPath = C:\Documents and Settings\BSPROG S\Desktop\DeVry \Previous work\BIS 440\ESSS_Case_S tudy.zip
var strPathArray = strPath.split(' \');
var strFileName = strPathArray[strPathArray.le ngth-1];

You can get the name in strFileName variable....
Jan 15 '07 #2
bsprogs
6 New Member
First, you split the string into string array using '\' and get its array length. Then get the penultimate string value.... Hope it works....Find below the example code..

var strPath = C:\Documents and Settings\BSPROG S\Desktop\DeVry \Previous work\BIS 440\ESSS_Case_S tudy.zip
var strPathArray = strPath.split(' \');
var strFileName = strPathArray[strPathArray.le ngth-1];

You can get the name in strFileName variable....
That worked perfectly! Thank you. :)
As I learn more of how the JavaScript functions work, I'll get the hang of it, haha.
Jan 15 '07 #3

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

Similar topics

6
6081
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to parse the filename. <form name='form1' method='POST' enctype='multipart/form-data' action='sub.asp'> <input type='text' name='title1' value='value1'> <input type='file' name='file1'>
21
18224
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML doc with script tag who's source is a javascript file. <HTML> <script src="javascript.js"></script> </HTML> Javascript.js
2
1530
by: NewUser | last post by:
I have to call a js function from asp. If the last portion which is the following code is omitted <% dim objFile Set objFile = Server.CreateObject("AspSmartUpLoad.SmartUpLoad") Call objFile.DownloadFile("\\Myserver\filename" , "video/x-ms-wmv", "myfile") set objFile = nothing
5
7776
by: mgershma | last post by:
Hi. Does anybody know how can JavaScript get the filename of the file it's located in? For example, file 'mike.js' contains several functions and variables. I would like to set the variable to the filename of this file dynamically:
8
3657
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
1611
by: pbd22 | last post by:
Hi. I am having a really tough time here and would appreciate some help. i am using an iFrame to pass a url string of files to upload to server. on the client i have created a multiple upload javascript using the below link: http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
3
19864
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be found at www.srmiles.com/freestuff/ajax_file_uploader/ . you can do multiple file uploads. each upload will have it's own "form"-tag, so that each file is uploaded for its own. could be a good solution if there are "big" uploads.
3
4736
by: Xzorius | last post by:
Hi, First of all, i wanna say i don't have a great knowledge about javascript. So, what i want to do is this: If a user press a button, a inputbox shows up. Untill here, no problem but now i want to put what that person entered in a textbox so i can use the texbox value. I am programming in ASP (not ASP.NET!!!). I used javascript to call the inputbox. I have no idea how to gow further now.
2
5091
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web design before all the CGI and PHP stuff got big, so I prefer to do things simply. The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button,...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.