473,562 Members | 2,613 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 15842
"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
5365
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...
3
1718
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...
4
1414
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...
2
1713
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
3001
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
3641
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
3
19845
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...
2
5613
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...
19
1721
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
7579
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...
0
8101
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...
1
7630
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...
0
7940
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...
1
5479
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...
0
3626
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...
1
2075
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
1
1192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
907
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...

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.