|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 | ||
|
Foldin' For PCMech!
|
javascript help
Hey guys, Im trying to make a random URL script for my webpage. Basically I want a random link to be displayed everytime the page is loaded. This is what I have but it is not showing up with anything on the website. What am I doign wrong? Im not very good with javascript, if you cant tell...
I couldnt add it to my post without it messing with things so I put it in a text file.
__________________
Eric
|
||
|
|
|
|
|
#2 |
|
Member (2 bit)
Join Date: Jan 2012
Posts: 2
|
Try swapping the ' and " around in the document.write statement. for example: ("some text"+ variable +"more text"); instead of ('text"'+variable+'"more text'); or escape the double quotes like this: \"
Last edited by Clutch X; 02-13-2012 at 07:08 PM. |
|
|
|
|
|
#3 |
|
Member (10 bit)
Join Date: Jan 2010
Location: N. Calif.
Posts: 529
|
Make sure all of your left parens ( have a matching right paren ). You have 4 lefts but only 2 rights in the line where you assign a value to random_num.
__________________
Been using, building, repairing and programming computers for nearly 30 years now. |
|
|
|
|
|
#4 |
|
Foldin' For PCMech!
|
i tried the suggestions and still can not get it to work. nothing is displayed at all.
|
|
|
|
|
|
#5 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Fixed and attached. Just rename the file and get rid of the .txt extension to run it in your browser as a webpage.
There were a few minor errors. There was an extra space in one of the script tags. The math library needs to be capitalized. I also included a new formula for generating the random array index. With this new formula, you can specify the range you want to use. If you use single-quote strings, you don't need to escape anything but a single quote. If you use double-quote strings, there's a handful of special characters you have to escape. Usually, when you're writing HTML within strings, it's best to use single-quotes because there are fewer symbols you need to escape.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
|
|
#6 |
|
Foldin' For PCMech!
|
Thank you Force, that did the trick!
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|