/    Sign up×
Community /Pin to ProfileBookmark

Retrieving file name with JavaScript

Hello,

I have a question. How can I get the name of a file in my website folder using JavaScript in an onClick attribute. Basically, when I click on the button, I need it to get the name of a certain file and copy it to a variable inside another function (I know how to do this, I just need to know how to get the file name).

Thank You

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledApr 19.2009 — something like this:
<i>
</i>&lt;img src='/imageDir/subdir/filename.jpg' onclick='var file = this.src.match(/w+.w{3,4}$/); if(file)[b]my_function(file[0]);[/b]' /&gt;
Copy linkTweet thisAlerts:
@jpfaletauthorApr 19.2009 — Thank you so much.
Copy linkTweet thisAlerts:
@jpfaletauthorApr 19.2009 — Could you just explain me what this means (it is a bit beyond my present knowledge of JavaScript:

(/w+.w{3,4}$/)

Thank you
Copy linkTweet thisAlerts:
@ZeroKilledApr 19.2009 — that is a literal [url=http://www.regular-expressions.info/javascript.html]regular expression[/url] which use a complete different syntax than javascript. it mean, to match a composition of one or more alphanumerical characters (w+) followed by a dot (.) and finally three or four alphanumerical chars (w{3,4}) anchored at the end of string ($).

regular expression are powerful for matching, searching or replacing content on a string. read more about it in the link.
×

Success!

Help @jpfalet spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...