473,403 Members | 2,183 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,403 software developers and data experts.

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.getElementbyId();
document.getElementbyName();
document.getElementbyTagName();
document.img[].src();

pls help
Jul 23 '05 #1
12 15823
"Sharad Gupta" <g_******@yahoo.com> wrote in message
news:7e**************************@posting.google.c om...
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.getElementbyId();
document.getElementbyName();
document.getElementbyTagName();
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.pathname;
var filename =
pathname.substr(pathname.lastIndexOf("\\")+1,pathn ame.length);
alert(filename);
}
function showpath() {
var pathname = location.pathname;
pathname = pathname.substr(1,pathname.length);
alert(pathname);
}
function showimage(that) {
alert(that.name);
}
</script>
</head>
<body>
<input type="button" value="Path+File" onclick="showpath()">
<input type="button" value="File Only" onclick="showfile()">
<img src="http://www.google.com/images/logo.gif" name="Google"
onclick="showimage(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.lastIndexOf("\\")+1,pathn ame.length);

This is redundant.
substr(startIndex [,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.lastIndexOf("\\")+1,
pathname.lastIndexOf("."));

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.lastIndexOf("\\")+1,
pathname.lastIndexOf(".")-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.lastIndexOf("/")+1,pathname.length);
document.getElementById("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.newsgroups.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.lastIndexOf("/")+1,pathname.length);
document.getElementById("disp").innerText = filename;

this gives filename(primary.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.lastIndexOf("/")+1,pathname.length);
document.getElementById("disp").innerText = filename;

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


var filename = pathname.split(".");
document.getElementById("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.lastIndexOf("/")+1,pathname.length);
var filename = filename.substr(filename,filename.lastIndexOf(".") );
document.getElementById("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.getElementById("disp").innerHTML = filename[filename.length-2]

"length-2"
Mick
Jul 23 '05 #10
Sharad Gupta wrote

ie we1234.xyz

i am getting xyz, where as i want we1234

var filename = pathname.split("/");
document.getElementById("disp").innerHTML =
filename[filename.length-1].split(".")[0]
Disregard earlier answer.
Mick
Jul 23 '05 #11
"Sharad Gupta" <g_******@yahoo.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
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


Were you waiting for me to respond?

Here's a variation of what I posted before.

Watch for word-wrap.

<html>
<head>
<title>show.htm</title>
<script type="text/javascript">
function showfile() {
var pathname = location.pathname;
var filename =
pathname.substr(pathname.lastIndexOf("\\")+1,pathn ame.length);
alert(filename);
}
function showpath() {
var pathname = location.pathname;
pathname = pathname.substr(1,pathname.length);
alert(pathname);
}
function showpref() {
var pathname = location.pathname;
var filename =
pathname.substr(pathname.lastIndexOf("\\")+1,pathn ame.length);
filename = filename.substr(0,filename.indexOf("."))
alert(filename);
}
function showimage(that) {
alert(that.name);
}
</script>
</head>
<body>
<input type="button" value="Path+File" onclick="showpath()">
<input type="button" value="File Only" onclick="showfile()">
<input type="button" value="File Pref" onclick="showpref()">
<img src="http://www.google.com/images/logo.gif" name="Google"
onclick="showimage(this)">
</body>
</html>
Jul 23 '05 #12
Thanks a lot..
it really solved my problem... other than this i also choked a function
with help of subStr and str.length.

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

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

Similar topics

1
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...
3
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. ...
4
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...
2
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...
2
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...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
3
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...
2
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,...
19
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-...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
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
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.