Home Events! Entrance Everyone Wiki Search Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
November 21, 2024 - @770.71 (what is this?)
Forum activity rating: Three Stars Posts: 33/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts    Start New Topic
News: :skull: Websites are like whispers in the night  :skull:

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Creating a random generator with results that I can format with HTML and CSS?


« previous next »
Pages: [1] Print
Author Topic: Creating a random generator with results that I can format with HTML and CSS?  (Read 741 times)
wygolvillage
Sr. Member ⚓︎
****


meow!!!

⛺︎ My Room
StatusCafe: wygolvillage
iMood: wygolvillage

View Profile WWW

Thanks for being rad!melonlands goth cat!First 1000 Members!Joined 2023!
« on: October 04, 2023 @560.61 »

Ok, so, I have a project I'm cooking up and one of the pages involves a random generator. I've found how to make one of those pretty easily but the problem is that all of the tutorials I've found just let me have text results, but I want to be able to have both text and images and- this is a little weird- have certain bits of text and some images determined with span class, so it can call to the stylesheet that's currently "active" (since the concept for this project prominently features a theme switcher) to find which names, images, text strings, etc. to display within the generated result. (Very sorry if this doesn't make any sense lol)

Apologies if this is extremely obvious to anyone who knows how to use Javascript since I most definitely do not, but... Is there a way to use HTML in the results that the generator can pick from?
Logged


TheFrugalGamer
Sr. Member ⚓︎
****


⛺︎ My Room
Itch.io: My Games

View Profile WWW

First 1000 Members!Pocket Icelogist!Joined 2022!
« Reply #1 on: October 04, 2023 @610.86 »

Yes, in general if you can print text, you can print anything else as well. Do you have an example of the javascript you're using that you could share?
Logged

wygolvillage
Sr. Member ⚓︎
****


meow!!!

⛺︎ My Room
StatusCafe: wygolvillage
iMood: wygolvillage

View Profile WWW

Thanks for being rad!melonlands goth cat!First 1000 Members!Joined 2023!
« Reply #2 on: October 04, 2023 @618.00 »

I was using some of the code examples from this thread.
Logged


TheFrugalGamer
Sr. Member ⚓︎
****


⛺︎ My Room
Itch.io: My Games

View Profile WWW

First 1000 Members!Pocket Icelogist!Joined 2022!
« Reply #3 on: October 04, 2023 @722.11 »

So assuming you're using this code:

Code
<script>
	      function myFunction() {
	      var r_text = new Array ();
	      r_text[0] = "a";
	      r_text[1] = "b";
	      r_text[2] = "c";
	      r_text[3] = "d";
	      var i = Math.floor(4*Math.random())
	      document.getElementById("text").innerHTML = r_text[i];
	      }
	</script>

You can place anything on the other side of "r_text[0] =" and have it print. So replace "a" with:

Code
<img src='source_here' class='myClass'> a, or whatever text you want to generate

and "b" and so forth with something similar. Sometimes apostrophes will confuse the code, so make sure if you're inside a pair of "", that you use '' instead, or leave them out altogether.
Logged

wygolvillage
Sr. Member ⚓︎
****


meow!!!

⛺︎ My Room
StatusCafe: wygolvillage
iMood: wygolvillage

View Profile WWW

Thanks for being rad!melonlands goth cat!First 1000 Members!Joined 2023!
« Reply #4 on: October 05, 2023 @537.77 »

It worked! Turns out I was using quotation marks instead of apostrophes... I had no idea that was what was messing it up  :ok:
Logged


TheFrugalGamer
Sr. Member ⚓︎
****


⛺︎ My Room
Itch.io: My Games

View Profile WWW

First 1000 Members!Pocket Icelogist!Joined 2022!
« Reply #5 on: October 05, 2023 @599.72 »

Awesome, so glad it came together! Javascript is pretty forgiving overall, but I still mess up the apostrophes on occasion.
Logged

Pages: [1] Print 
« previous next »
 

Vaguely similar topics! (3)

Earthbound Text Generator

Started by ObspogonBoard ♖ ∙ Video Games

Replies: 7
Views: 4798
Last post March 04, 2023 @848.91
by sig
HELP: Unity/C# Random Weather Script

Started by cinniBoard ☔︎ ∙ I need Help!

Replies: 1
Views: 1356
Last post May 17, 2022 @786.75
by Melooon
HTML Journal and the Neon Kiosk (Easy RSS feeds for site news)

Started by m15oBoard ♺ ∙ Web Crafting Materials

Replies: 12
Views: 3519
Last post April 24, 2023 @816.79
by shevek

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi