Jump to content

Thunderforge

Members
  • Posts

    5
  • Joined

  • Last visited

Thunderforge's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I want to randomly generate an src path for an image, for example; src = <var1>/<var2>.gif I'm sure it can be done, but not sure at what level it would go in. This is what I have; var huePick =[{text:'light',image:'light'},{text:'dark',image:'dark'}]; var colourPick =[{text:'green',image:'green.gif'},{text:'red',image:'red.gif'}]; function myFunction() { var hueChosen= huePick [Math.floor(Math.random()*huePick.length)]; var colourChosen= colourPick [Math.floor(Math.random()*colourPick.length)]; document.getElementById("thisResult").src = hueChosen.image / colourChosen.image; } The id called 'thisResult' I want to be able to use as a url I can drop into an image tag. Which would look like this; dark/green.gif and locate the relevant image in the relevant folder. (I know I could reference them all in one folder with one long variable but I have reasons why not to) How do I arrange the getElementById string and implement it into an image tag? Does any of that make sense? (Obviously I would have a corresponding file structure with different gifs in the light folder to those in the dark folder, but with same names.)
  2. Haha! You guys are awesome!! :-D I haven't exactly done what you each suggested but I've got what I wanted and needed everything you all said! [@dsonesuk - that is a very eloquent way of condensing it, which I like very much; but in the bigger project this is all going into would probably be too restricting for me.] Here is my final code; <html> <button onclick="justTextFunc()">COLOUR</button><br> <span id="justChoseText"></span><br> <img id="justChosePic" src="" alt="Click the button!"> <script> var justText = [{text: 'RED', image: 'Red.gif'}, {text: 'GREEN', image: 'Green.gif'}, {text: 'BLUE', image: 'Blue.gif'}, ]; function justTextFunc() { var pickText = justText [Math.floor(Math.random()*justText.length)]; document.getElementById("justChoseText").innerHTML = pickText.text; document.getElementById("justChosePic").src = pickText.image; } </script></html>
  3. I didn't know you could combine different types of thing in a variable! Of course I don't know how to separate the parts again afterwards... This is my code, presumably I need a function to id the image as well? <html> <button onclick="someFunction()">COLOUR</button> <br> <text id="chooseColour"></text> <img id="chooseColour"></img> <script> var colourText = [ {text: 'RED', image: 'Images/Red.gif'}, {text: 'GREEN', image: 'Images/Green.gif'}, {text: 'BLUE', image: 'Images/Blue.gif'}, ]; function someFunction() { var pickColour = colourText [Math.floor(Math.random()*colourText .length)]; document.getElementById("chooseColour").innerHTML = pickColour; } </script></html>
  4. Hi, can anyone help me with this - I keep drawing blanks! A button which throws up a random word from an array, which is fine, I've got that. But I want it to also display an image based on that result, i.e.; from var colourPicker('red','blue','green'); then if, for example, text=='red' then the image displayed is Red.gif I'm sure it's simple to do but I can't get it to work! Any help would very much be appreciated. Thanks, Thunderforge
  5. Hello! I'm Thunderforge, I don't know much about html, but learning slowly!
×
×
  • Create New...