[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

javascript/html button

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 6
Thread images: 1

Hi. I'm new to javascript and something doesn't seem to be functioning right.

What I'm trying to make is a website that will spit out a movie (from an array) when clicking on a button.

In the picture you can see the website, as well as the javascript (top) and the html (bottom).

Is there something wrong with the javascript or did I not link it correctly to the button? Or do I need to give the website somewhere to display the movie name, like a text box?

Thanks
>>
>>163785
first of all, inline JS like that is looked down upon
>onclick="pickMovie()"

second, all the function does is create a variable (randomValue) and define it, nowhere does it display it

third, you are not properly quoting the items in your array. Array items must be quoted with either single or double quotes:
> ' '
> " "
it looks like you are using a comma to start the quote

fourth, do not add a comma after the final item in an array, it has a chance to cause major issues in some browsers.

I have made a JS Fiddle that works properly, please note the changes made to the HTML as well (adding IDs and another P element to write the return value inside of)

https://jsfiddle.net/jaketr00/8xzsk6sd/1/
>>
>>163785
1. Open it in your browser and open the console (F12), that'll show you errors.

2. Your Movies array is messed up, each string value should be enclosed in single quotation marks, separated by one comma. Like: var Movies = ['Castle in the Sky', 'Grave of the Fireflies', 'My Neighbor Totoro'];

3. Yes, you have to display your randomValue somewhere somehow, else it's just another variable like Movies. Try this: alert(randomValue);
>>
>>163793
>>163793
Thank you two.

The quotation is probably from my text file, which I keep the list in. German programs change the first quotation mark.
I didn't think it'd be a problem, thank you for telling me.
>>
>>163806
>German programs change the first quotation mark
I recommend using Brackets by Adobe, its made for web code.
http://brackets.io/
>>
>>163811
I use sublime text, and it seems to work fairly well.
The problem I had was that I kept the list in a regular text program, simply to store it somewhere.
Thanks though.
Thread posts: 6
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.