/    Sign up×
Community /Pin to ProfileBookmark

Is this possible

My server does not allow SSI so I’m trying to find out if this can be done in Javascript. I want to randomly pick 7 lines of text from a file and then display them on a page.

Ideally, I’d like to have a button to call the script again so that the user does not have to refresh the page as this will be displayed near the bottom of the page.

Can this be done?

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJul 09.2004 — I am not really sure if this is the way to go as your lines of text would have to go in an array but here's what I played with

<script>

txt=new Array()

txt[0]="Line 1"

txt[1]="Line 2"

txt[2]="Line 3"

txt[3]="Line 4"

txt[4]="Line 5"

txt[5]="Line 6"

txt[6]="Line 7"

txt[7]="Line 8"

txt[8]="Line 9"

txt[9]="Line 10"

function generate(){

oSelect=7 // how many

Total=txt.length-1

Numbers_Range=new Array()

Selected_Num=new Array()

document.getElementById("display").innerHTML=""

for(n=0;n<Total+1;n++){

Numbers_Range[n]=n

}

for(p=0;p<oSelect;p++){

rndnum=Math.round(Math.random()*(Total))

Chosen_Number=Numbers_Range.splice(rndnum,1)

Total--

ShowMe(Chosen_Number)

}

}

function ShowMe(Chosen_Number){

document.getElementById("display").innerHTML+=txt[Chosen_Number]+"<br> "

}

onload=generate

</script>

<div id="display">---------</div>

<a href="#null" onclick="generate()">Show Text</a>
Copy linkTweet thisAlerts:
@keithh0427authorJul 09.2004 — Problem is I need it from a file, not embedded in the script. I have over 900 lines in the file. Wouldn't that be too much overhead each time the page loaded? I'm a newbie so maybe it's OK.
Copy linkTweet thisAlerts:
@CharlesJul 09.2004 — [font=georgia]1) JavaScript cannot communicate with the external world except through the user.

2) Not everybody uses JavaScript.[/font]
Copy linkTweet thisAlerts:
@keithh0427authorJul 09.2004 — Can it be done with Javascript making a call to a CGI program?
Copy linkTweet thisAlerts:
@russellJul 09.2004 — 2) Not everybody uses JavaScript.[/QUOTE]

In most web applications, at least business web applications, these users can be safely ignored. Try ordering something online, or checking your bank balance without JavaScript enabled. It is ok to tell users that JavaScript (and cookies) are required to use your site. However, you shouldn't require it unless it is truly necessary.
Copy linkTweet thisAlerts:
@CharlesJul 09.2004 — [font=georgia]JavaScript cannot do that and, as I mentioned above, you shouldn't use JavaScript for this even if it could.

Since you do have CGI capability, use an IFRAME element to fetch the line as a complete HTML document generated by your server side script.[/font]
Copy linkTweet thisAlerts:
@CharlesJul 09.2004 — [i]Originally posted by russell [/i]

[B]In most web applications, at least business web applications, these users can be safely ignored. Try ordering something online, or checking your bank balance without JavaScript enabled. It is ok to tell users that JavaScript (and cookies) are required to use your site. However, you shouldn't require it unless it is truly necessary. [/B][/QUOTE]
[font=georgia]And if someone is using a Braille browser that doesn't support JavaScript?

"[b]6.3[/b] Ensure that pages are usable when scripts, applets, or other programmatic objects are turned off or not supported. If this is not possible, provide equivalent information on an alternative accessible page. [Priority 1]"

[url=http://www.w3.org/TR/WCAG10/wai-pageauth.html][i]Web Content Accessibility Guidelines 1.0[/i][/url]

And if you're in the USA then there's a little matter of the Americans with Disabilities Act requiring certain entities to be accessible. Buisnesses are expressly one of these.[/font]
Copy linkTweet thisAlerts:
@keithh0427authorJul 09.2004 — OK. I have a .pl script that does what I need it to do. How would I include that within an HTML document using IFRAME or any other method?

Can that be done?
Copy linkTweet thisAlerts:
@russellJul 09.2004 — And if someone is using a Braille browser that doesn't support JavaScript?[/QUOTE]
I'm not saying not to provide alternate content. I'm saying that when client-side code is the right tool for the job then use it -- without worrying about the perhaps 2% of users who don't have JS enabled user-agents not getting the full effect. Tell them that to fully utilize your site they need JavaScript. If it is mission critical content, then JS probably shouldn't be manipulating it. Otherwise, script away. And as I said, you need to be sure it's truly necessary to require it before you do so.

Anyway, I don't suppose any of this helps answer the original question...
Copy linkTweet thisAlerts:
@russellJul 09.2004 — Make the CGI the action of a form.
×

Success!

Help @keithh0427 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.17,
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,
)...