News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Getting my random picker script to work on-site

Started by Sigyn, December 04, 2016, 07:36:35 PM

Previous topic - Next topic

Sigyn

Hello. I'm having trouble getting my small code to work.

This is the contents of the code, and I made an HTML page to use with the Page Management mod which allows for making HTML pages that you can use on the site.

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>Title</title>

  <link rel="stylesheet" href="style.css"/>
  <style>textarea {
  width: 50%;
  display: block;
  height: 150px;
}
#result {
  display: block;
}</style>
</head> <body>
<textarea id="input" placeholder="Put a list of things here"></textarea>
<button id="click">Pick one</button>
<output id="result"></output> 

  <script>document.getElementById('click').onclick = function() {
var input = document.getElementById('input').value;
  var items = input.split(/[,\n]/);
  var count = items.length;
  var index = Math.floor(Math.random()*count);
  var selected = items[index];
  document.getElementById('result').value = selected;
};</script>
</body>
</html>


But when I put that in the page and save it, the code doesn't function. I attempted to make a SimplePortal block of it as well using the above code, but still the script wouldn't display the result as it does in my JSFiddle link. Is there some way I can get it to work? Something I'm missing perhaps?

Ideally I would like it to work as a SimplePortal block if that helps anything.

Illori

the page already has the html tags defined as well as the header and opening body tags, you just need to add the content of the body. really you should be posting questions like this in the support topic for the mod(s) you are using.

Sigyn

I would, except it's not an issue with the mods. Because other things work on them... for some reason this is an issue with why the forum wont display a result with this code.

Illori

but you are using a mod, so you need to post in the mods support topic for help with the issue you are facing. you state you want to put the code in a mod in your post... that right there means you need to post in the mods support topic so that they can help you with your code.

Advertisement: