/    Sign up×
Community /Pin to ProfileBookmark

Getting files randomly

I have on my server about ten files that are to be made available to users, by their downloading them, from my website. Using html I can get the user to download a specific file with the code <a href=”Filename.typ”>textlink</a>.

However I want to be able to produce code (either <script> or HTML that will facilitate the downloading of a random file from the ten available.

What would the code be?
Can anyone help?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 15.2006 — A server-side code solution would be more reliable. For a JavaScript solution, you could list the ten files in a JavaScript array and then do this:

<a href="Filename.typ" onclick="

var idx = Math.floor(Math.random() * aryFiles.length);

this.href = aryFiles[idx];

return true;">textlink</a>
Copy linkTweet thisAlerts:
@VillanescaauthorMay 15.2006 — Many thanks Phpnovice for your reply. I will try it and see if it works for me. I cannot do a server-side solution because my programming skills do not stretch that far!

Thank you again.

Villanesca
×

Success!

Help @Villanesca 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...