473,836 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript for capturing filename

i have this problem of capturing the filename on the instance when
onclick is activated in the <body>
the function should catch the filename and display it.

Second problem, i have to catch the image name in the same fashion
using =onclick showimage(this) . Is this possible at at
I have tried all combinations of
document.getEle mentbyId();
document.getEle mentbyName();
document.getEle mentbyTagName() ;
document.img[].src();

pls help
Jul 23 '05 #1
12 15872
"Sharad Gupta" <g_******@yahoo .com> wrote in message
news:7e******** *************** ***@posting.goo gle.com...
i have this problem of capturing the filename on the instance when
onclick is activated in the <body>
the function should catch the filename and display it.

Second problem, i have to catch the image name in the same fashion
using =onclick showimage(this) . Is this possible at at
I have tried all combinations of
document.getEle mentbyId();
document.getEle mentbyName();
document.getEle mentbyTagName() ;
document.img[].src();

pls help


Will this help? Watch for word-wrap.

<html>
<head>
<title>show.htm </title>
<script type="text/javascript">
function showfile() {
var pathname = location.pathna me;
var filename =
pathname.substr (pathname.lastI ndexOf("\\")+1, pathname.length );
alert(filename) ;
}
function showpath() {
var pathname = location.pathna me;
pathname = pathname.substr (1,pathname.len gth);
alert(pathname) ;
}
function showimage(that) {
alert(that.name );
}
</script>
</head>
<body>
<input type="button" value="Path+Fil e" onclick="showpa th()">
<input type="button" value="File Only" onclick="showfi le()">
<img src="http://www.google.com/images/logo.gif" name="Google"
onclick="showim age(this)">
</body>
</html>
Jul 23 '05 #2
Wow that solved my problem to the gr8 extent.

What I wanted exactly is that the script function should only pick the
primary name of the filename. Example.. if the file name is we1234.xyz
The function should pick we1234 and display on alert.

Pls help

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
> pathname.substr (pathname.lastI ndexOf("\\")+1, pathname.length );

This is redundant.
substr(startInd ex [,endIndex]).
endIndex is optional.
If endIndex is omitted, the substr goes to the end.

To get rid of your extention try this.
filename = pathname.substr (pathname.lastI ndexOf("\\")+1,
pathname.lastIn dexOf("."));

I don't remember off hand if substr includes the character at lastIndex or
not. If so, subtract one from the endIndex argument.
filename = pathname.substr (pathname.lastI ndexOf("\\")+1,
pathname.lastIn dexOf(".")-1);
Jul 23 '05 #4
this has solved my problem. Either when we do alert or pass the result
to some div or span, it shows the primary name of the filename.

function showfile(that) {
var pathname = that.src;
var filename =
pathname.substr (pathname.lastI ndexOf("/")+1,pathname.l ength);
document.getEle mentById("disp" ).innerText = filename;
Thanks for your help
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Sharad Gupta <g_******@yahoo .com> wrote in message news:<41******* *************** @news.newsgroup s.ws>...
Wow that solved my problem to the gr8 extent.

What I wanted exactly is that the script function should only pick the
primary name of the filename. Example.. if the file name is we1234.xyz
The function should pick we1234 and display on alert.

Pls help

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

The prev ex. solved the problem, with some changes done.
But still I can have the filename as we1234.xyz & not as we1234, what
I want to achieve. Actually I want to give the primary part of
filename as the name of the picture, so that I donr have to put in the
picture name again n again for 1000's of them. So i found the result
thru

var filename = pathname.substr (pathname.lastI ndexOf("/")+1,pathname.l ength);
document.getEle mentById("disp" ).innerText = filename;

this gives filename(primar y.ext), but I want only primary name.
thanks and waiting for reply
Jul 23 '05 #6
Sharad Gupta wrote:

[snip]

var filename = pathname.substr (pathname.lastI ndexOf("/")+1,pathname.l ength);
document.getEle mentById("disp" ).innerText = filename;

this gives filename(primar y.ext), but I want only primary name.
thanks and waiting for reply


var filename = pathname.split( ".");
document.getEle mentById("disp" ).innerHTML = filename[filename.length-1]
Mick
Jul 23 '05 #7
hi

thru the code i am able to generate the filename extension and not the
primary name of the filename.

ie we1234.xyz

i am getting xyz, where as i want we1234

still waiting
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
Sharad Gupta <g_******@yahoo .com> wrote:
thru the code i am able to generate the filename extension and not the
primary name of the filename.
ie we1234.xyz
i am getting xyz, where as i want we1234


function showfile(that) {
var pathname = that.src;
var filename =
pathname.substr (pathname.lastI ndexOf("/")+1,pathname.l ength);
var filename = filename.substr (filename,filen ame.lastIndexOf ("."));
document.getEle mentById("disp" ).innerText = filename;
}

works with "lulu.lili_lolo .jpg"
............... ..^
--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jul 23 '05 #9
Sharad Gupta wrote:

ie we1234.xyz

i am getting xyz, where as i want we1234

still waiting


var filename = pathname.split( ".");
document.getEle mentById("disp" ).innerHTML = filename[filename.length-2]

"length-2"
Mick
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5389
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
3
1730
by: sparks | last post by:
They have a new data collection station. The people here are using access 97.... This third party site will only post data back to us when we do this. http://www.datastuff.com/cgi-bin/ocs?Lo=yourname&Rpt=703&Month=7-5&Select=CC this is posted back to us as a file called data. There is no extension to is so the first thing that IE does is ask to save and where.
4
1426
by: Steve Wolfie | last post by:
Hello all: Again, let me thank everyone who has helped in the past. Can't wait till I can help out with some advice of my own. Now, I am building an app that wishes to retrieve the output of Google Desktop. It is very simple, I wish to send an http request asking for the results in XML. ( by adding &format=xml to the end of the url) i would like to capture the response from the Google Desktop server, (on the local machine) and save...
2
1732
by: Ken Cox - Microsoft MVP | last post by:
I'm trying to find a way to program in ASP.NET 2.0 but capture the HTML output. I found the following routine in ASP.NET 2.0 Cookbook from O'Reilly. It doesn't work if I include a server-side dropdownlist control on the page. The error is RegisterForEventValidation can only be called during Render(); Any ideas? Ken Microsoft MVP
2
3017
by: sergio | last post by:
i have a huge database that contains large amounts of html that i need to translate to ascii.. i have tried using html2text.py: http://www.aaronsw.com/2002/html2text/ but i could not figure out how to import it and use it as a library without getting errors everywhere..
8
3682
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
3
19886
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.
2
5624
by: san123456789 | last post by:
Hi.. I am trying to capture the graphics of a usercontrol.... using the following code.. //DLL import private static extern bool BitBlt( IntPtr hdcDest, // handle to destination DC int nXDest, // x-coord of destination upper-left corner int nYDest, // y-coord of destination upper-left corner
19
1747
by: Prisoner at War | last post by:
Okay, Folks, I guess my real burning concern all along is a "high-level" one: just how does JavaScript interact with CSS? Right now, my newbie self only knows JavaScript and CSS to *co- exist*...but I'm beginning to get the sense that they actually interact -- or, perhaps more precisely, JavaScript acts upon CSS...but how, exactly??
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10559
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...
1
10601
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9388
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...
1
7794
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5652
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
4460
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
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
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.