The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Random Message

View previous topic View next topic Go down

Solved Random Message

Post by Thistle on June 7th 2017, 7:14 am

Hello, could you please help me with making a random message script? I want it to be on all pages, where the standard View posts since last visit • View your posts • View unanswered postsMark all forums read are. Where would I put the script?

I've found a script. Would this do?
Code:
<script language="JavaScript"><!-- 
var h=(Math.random()*10); 
  if (h <1) document.writeln(""); 
  if (h > 1 && h < 2) document.writeln(""); 
  if (h > 2 && h < 3) document.writeln(""); 
  if (h > 3 && h < 4) document.writeln(""); 
  if (h > 4 && h < 5) document.writeln(""); 
  if (h > 5 && h < 6) document.writeln(""); 
  if (h > 6 && h < 7) document.writeln(""); 
  if (h > 7 && h < 8) document.writeln(""); 
  if (h > 8 && h < 9) document.writeln("'"); 
  if (h > 9 && h <10) document.writeln(""); 
// --></script>

Thank you kindly.


Last edited by Thistle on June 20th 2017, 12:24 pm; edited 1 time in total
avatar
Thistle
New Member

Posts : 14
Reputation : 2
Language : English

http://www.makemysimsreal.com/

Back to top Go down

Solved Re: Random Message

Post by Ange Tuteur on June 7th 2017, 4:40 pm

Hi @Thistle,

I'd recommend using the following script instead, since it'll be easier to manage.
Code:
$(function() {
  var message = [
    'Message 1',
    'Message 2',
    'Message 3',
    'Message 4',
    'Message 5',
    'Message 6',
    'Message 7',
    'Message 8',
    'Message 9',
    'Message 10'
  ],
 
  box = document.querySelectorAll('.random-message-box'),
  i = 0,
  j = box.length;

  for (; i < j; i++) {
    box[i].innerHTML = message[Math.floor(Math.random() * message.length)]
  }

  'par ange tuteur';
});
It should be added in JavaScript codes management (AP > Modules > JS > New) with a placement of "in all the pages." You can add as many messages as you want btw. If you want less, delete the existing messages, if you want more add a comma after the last message and create a new string. See "Array" for more information on how arrays are formatted and accessed.

As for displaying your random messages, add this tag anywhere that HTML formats :
Code:
<div class="random-message-box"></div>
With how the script is programmed, you can paste this tag multiple times to show multiple messages, each which are random. You don't need to use the DIV tag either, you can use any tag you want so long as it has
Code:
class="random-message-box"
.

As for the specific placement of your message, your best option would be to add it into the overall_header template or announcements, because they're visible on all pages.
avatar
Ange Tuteur
Forumaster

Male Posts : 13174
Reputation : 2873
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Random Message

Post by Thistle on June 13th 2017, 11:10 am

Thank you so much @Ange Tuteur. I am using your FAE, will this work with the theme? Thank you in advance.
P.S. Also how to design it the way "homepage message" is designed in FAE?

P.S. I tried it, it broke the theme chooser.
avatar
Thistle
New Member

Posts : 14
Reputation : 2
Language : English

http://www.makemysimsreal.com/

Back to top Go down

Solved Re: Random Message

Post by ounce on June 13th 2017, 3:49 pm

Sorry. No message here.
avatar
ounce
New Member

Posts : 5
Reputation : 1
Language : english

Back to top Go down

Solved Re: Random Message

Post by Ange Tuteur on June 13th 2017, 5:12 pm

Could you post your modified script here ? I've no issue on my test forum.
http://themedesign.forumotion.com/ (see the homepage message)

@Thistle wrote:Thank you so much @Ange Tuteur. I am using your FAE, will this work with the theme? Thank you in advance.
P.S. Also how to design it the way "homepage message" is designed in FAE?
The script will work regardless of forum version.

I'm not sure I comprehend ? Do you mean the standard block style ? If so, this is the HTML for it :
Code:
<div class="content-block">
  <div class="title">Block title</div>
  <div class="txt-content">everything else here</div>
</div>
avatar
Ange Tuteur
Forumaster

Male Posts : 13174
Reputation : 2873
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Random Message

Post by Thistle on June 19th 2017, 1:13 pm

@Ange Tuteur, yes, thank you.
I tested everything again. I put the code to announcements (the HTML one) and put the Java in the Java section. When I tried to modify the message, if I put a link there (using HTML) or somewhat longer message, it would break the design and the theme chooser would disappear.
Thank you in advance.

UPD: Just a link works, but a longer message does not.
avatar
Thistle
New Member

Posts : 14
Reputation : 2
Language : English

http://www.makemysimsreal.com/

Back to top Go down

Solved Re: Random Message

Post by Ange Tuteur on June 19th 2017, 3:58 pm

@Thistle does your message contain an apostrophe ? ( ' ) In JavaScript texts, messages, characters, etc.. wrapped with quotes or apostrophes are called "Strings." When you use the same type of quote/apostrophe inside a string that you constructed it with, it'll close the string early. For example :
Code:
'That is a String.'; // good
'That\'s a String.'; // good ; the apostrophe is escaped so the string doesn't end
'That's a String.'; // bad ; throws an error, ending the string at "That"

Basically all you need to do is escape the quote/apostrophe depending on which character you used to construct your string. To do that you use the escape character : \. See the examples below.
Code:
'That\'s escaped.';
"<a href=\"#\">Escaped</a>";

If you don't escape these characters then the string will end early and throw an error.


If possible, could you post the script here with your modified messages ? I can help debug it for you if you'd like.
avatar
Ange Tuteur
Forumaster

Male Posts : 13174
Reputation : 2873
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Random Message

Post by Thistle on June 20th 2017, 12:24 pm

Hello again, @Ange Tuteur. I think I managed to make it work! Thank you so much
avatar
Thistle
New Member

Posts : 14
Reputation : 2
Language : English

http://www.makemysimsreal.com/

Back to top Go down

Solved Re: Random Message

Post by Draxion on June 20th 2017, 2:30 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1561
Reputation : 200
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum