PDA

View Full Version : How do I generate a "random" URL link??



pminuk
03-24-2003, 01:59 AM
I have written code using the math.random which worked once for generating a (random) quote from a list of statesman, this time I want to use a hypertext link so the user can click it and arrive at the site...


the browser doesnt report any "errors" & I've been staring at it far to long to be able to figure out what is wrong!! can anyone assist?


<script language="javascript">
QuoteArray = new Array(



" <A href='http://www.rice.edu/~jenky/caryn/protein.html'>Protein Requirements for Athletes</a> -- Rice.edu " ,
" <A href='http://www.rice.edu/~jenky/sports/Insulin.athlete.html'>Insulin, Diet, Disease and Athletes</a> -- Rice.edu " ,
" <A href='http://www.rice.edu/~jenky/sports/calcium.html'>Calcium, Bones and Stress Fractures</a> -- Rice.edu " ,
" <A href='http://www.rice.edu/~jenky/sports/dehydration.html'>Dehydration and Heat Injury</a> -- Rice.edu " ,
" <A href='http://www.runnertriathletenews.com/tips/39.html'>Helping Fat People Get Fit</a> -- Runnertriathletenews.com " ,
" <A href='http://www.peakhealth.net/article.cfm?article_id=12440&action=article'>Nutritional Relief for Joint Pain</a> -- Peakhealth.net " ,
" <A href='http://www.peakhealth.net/article.cfm?article_id=12403&action=article'>Becoming A Bigger, Stronger, Healthier Athlete</a> -- Peakhealth.net " ,
" <A href='http://www.peakhealth.net/article.cfm?article_id=12452&action=article'>Eating for Peak Performance</a> -- Peakhealth.net " ,
" <A href='http://www.runnersworld.com/nutrition/nusweets.html'>How to Get the Most Out of Sugar Fixes</a> -- Runnersworld.com " ,
" <A href='http://www.runnersworld.com/nutrition/nuprotei.html'>Protein Primer</a> -- Runnersworld.com " ,
" <A href='http://www.runnersworld.com/nutrition/nubrainfood.html'>Fuel Your Brain</a> -- Runnersworld.com " ,
" <A href='http://www.runnersworld.com/nutrition/nuliztop10.html'>Top 10 Nutrients</a> -- Runnersworld.com " ,
" <A href='http://www.runnersworld.com/nutrition/nudefense.html'>Defensive Eating: How to Prevent Future Eating</a> -- Runnersworld.com " ,
" <A href='http://www.firstpath.com/scripts/wsisa.dll/story.html?article=1895'>Getting the Skinny on Fats</a> -- Firstpath.com " ,
" <A href='http://www.firstpath.com/scripts/wsisa.dll/story.html?article=1897'>Tips for Controlling the "F" Word</a> -- Firstpath.com " ,
" <A href='http://www.fitrex.com/articles/article165.html'>Cutting Fat Wisely</a> -- Fitrex.com " ,
" <A href='http://www.fitrex.com/articles/article170.html'>Where's The Fat?</a> -- Fitrex.com " ,
" <A href='http://www.newimagefitness.com/Fat06.html'>How Much Fat Is Too Much?</a> -- Newimagefitness.com " ,
" <A href='http://vm.cfsan.fda.gov/~dms/fdfatout.html'>Taking the Fat Out of Food</a> -- Vm.cfsan.fda.gov " ,
" <A href='http://vm.cfsan.fda.gov/~dms/fdfats.html'>A Consumer's Guide to Fats</a> -- Vm.cfsan.fda.gov " ,
" <A href='http://www.runnersworld.com/nutrition/nufatwant.html'>The Fat You'll Want</a> -- Runnersworld.com " ,
" <A href='http://www.fitnesszone.com/library/aerobic7.html'>How Do I Know When I'm Exercising Hard Enough to Burn Fat?</a> -- Fitnesszone.com " ,
" <A href='http://www.simplefitnesssolutions.com/articles/fat_burning.htm">The Skinny on Fat Burning</a> -- Simplefitnesssolutions.com " ,
" <A href='http://www.runnersworld.com/nutrition/nufatasfuel.html'>Fat as Fuel</a> -- Runnersworld.com " ,
" <A href='http://www.runnersworld.com/nutrition/nuburnfat.html'>Fat Burning is a Simple Matter</a> -- Runnersworld.com " ,
" <A href='http://www.cspinet.org/nah/6_99/transfat3.html'>TransFat</a> -- Cspinet.org " ,

);
RandomNo = Math.floor(QuoteArray.length * Math.random());
document.write("<b>" + QuoteArray[RandomNo] + "</b>");
</script>

Thanks!!

Peter
(hard to code when ya have only 1 brain cell haha)

glenngv
03-24-2003, 02:19 AM
you have an excess comma at the last item in the array:

Cspinet.org " ,
);

pminuk
03-24-2003, 02:23 AM
grrrr, it's not my day,
Thank you for spotting the bonheaded error of the day, I fixed that and to my chagrin it still isnt working?

Is there a coffee shop still open anyware?

Peter

pminuk
03-24-2003, 02:28 AM
thank youuuuu

after going thru the code after a break I spotted some extra quote marks, around line 30, that was the charm!!

thanks for the fresh set of eyes

Peter
(needs a beer)

glenngv
03-24-2003, 02:39 AM
you should turn on script error notification to help you debug easily.