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.

Using Javascript in Forumotion

View previous topic View next topic Go down

Solved Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 7:41 pm

Hi, so I'm pretty new to HTML/Javascript in general but have extensive Java, C, C++, etc programming background. I'm wondering how I can use javascript in posts for my forum. I tried doing this simple test to try and set and display a variable, however all of the portions inside the <script> tags just got spat out to the post and not actually processed. Am I not understanding something important here?

Code:
<html>
<head>
<script type="text/javascript">
var city1 = "Dalas and San Francisco";
</script>
</head>
<body>
<script type="text/javascript">

 document.write(city1);

</script>
</body>
</html>

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by SLGray on September 18th 2014, 7:58 pm

Administration Panel > Modules > HTML/JavaScript
JavaScript Management


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 35661
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 18th 2014, 7:59 pm

2 things.

#1. Do you have HTML enabled on your forum and prefences?

#2. I don't think JavaScript works on topics, not too sure though.

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 8:08 pm

Thank you for the quick replies!

I do have HTML enabled. Also I looked around on here and saw the whole JavaScript Management thing, but how do I use that in actual posts?

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by SLGray on September 18th 2014, 8:17 pm

When you create a JavaScript, you will check the in the post option.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 35661
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 18th 2014, 8:48 pm

Make sure you tick the Enable JavaScripts option to yes

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 10:35 pm

Enable JavaScript is checked off.

SLGray: I'm not sure what you're referring to. There doesn't appear to be any option to use a javascript when posting a reply.

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 18th 2014, 10:43 pm

Tick JavaScript on and press the green + button to add a JavaScript

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 10:46 pm

As I said, I already enabled javascript and have added my script to the list. The problem I'm having now is actually using those scripts within posts

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by SLGray on September 18th 2014, 11:19 pm

When you create a JavaScript, there should be an option for In the Posts at the top.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 35661
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 11:28 pm

Ok, I'm looking at one javascript and I see what you're talking about. I already have "In all the pages" checked off, but I still don't see quite how to use it. Essentially, what I'm wondering is how to display city1 (as seen in my original post) in the body of a post. What this script will eventually do is allow a number to be set inside a post and then have a result based on calculations using that number. For example:


the javascript will define function(x){return x+1}. The body will then be able to call function(10) and in its place the number 11 should be inserted.

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by SLGray on September 18th 2014, 11:41 pm

I do not see the function in your JavaScript thought.

It looks like you used HTML coding.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 35661
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 18th 2014, 11:47 pm

Yup, I know it's not there. The code I posted is just a test example. I haven't done the real code yet because I want to know how I will be using it first. For the sake of argument though, let's say my Javascript says exactly this:

Code:
functionmult2(a) {returna * 2;}

Now let's say in a post I want to use this. How should I do so?

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 20th 2014, 5:50 pm

bumpcat

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 20th 2014, 5:54 pm

Your javascript should have a function which relates to an existing bbcode. Though I'm not sure if you can create your own bbcodes.

However in case that is a CSS ruling, you place it in your CSS stylesheet.

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 20th 2014, 6:03 pm

Sorry for being so dull, but I'm not sure exactly what you mean :/. How do I relate my function to existing bbcode? All I need it to do is extract a variable and then replace that variable with a block of text (in the example above, that block would simply be the result of an algorithm). I saw on another site that one way to do this is with tag IDs, as shown below;

Code:
functionmult2() {
var num = document.getElementById('NUM').innerHTML;
var det = "" + num*2;
document.getElementById('NUM').innerHTML = det;
}

And then in the post to do something like this:

Code:
<html>
<body>
<p id='NUM'>5</p>
</body>
</html>

But the question still remains how to make the actual function run.

Also I'm not sure how this relates to CSS either. Again, I apologize, I'm not very familiar with webware ><

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 20th 2014, 6:07 pm

I apologize as I am not too big of a coder. It seems that you want to post your message with HTML via a JavaScript you've already implemented.

Now, are you completely sure that you have HTML enabled in your preferences? It doesn't matter if you have it enabled in the administration panel.

Profile => Preferences

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 20th 2014, 6:09 pm

Yup, html is on in both my profile and the admin panel

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ramdaman on September 20th 2014, 6:19 pm

I'm sorry then, I do not know what to do. You must await for the Forumotion Staff to help you out on this issue.

Ramdaman
Active Poster

Male Posts : 1614
Reputation : 96
Language : English, Albanian, Macedonian, Russian | HTML, CSS
Location : New York City

http://ndihme.forumotion.com/forum

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ange Tuteur on September 20th 2014, 8:38 pm

Hi,

You cannot format scripts to run in message content. This is restricted for your security to prevent XSS exploits. You can add scripts in the following areas :


  • JS management (Modules > JavaScript Code Management)
  • Templates (Display > Templates), for best usage add scripts to the footer so they run when the doc is ready.
  • Homepage message, for homepage scripts
  • Widgets (Modules > Forum widgets management)

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 20th 2014, 8:42 pm

Hm, so is there really no way to do what I'm trying to? I know I've seen scripts that can modify message content (see below), so I feel like there should be a way.

http://help.forumotion.com/t115281-how-to-take-off-the-colon-in-spoilers

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ange Tuteur on September 20th 2014, 8:51 pm

Are you just wanting to modify the posts with JavaScript ? You should do that here :
Administration Panel > Modules > JavaScript Codes Management > Create a new script

Title : Your choice
Placement : In the topics

The placement of the script depends where it executes. For example if I wanted to change the background of all posts I could write :
and stick it only in the topics
Code:
$(function() {
 var p = document.getElementsByTagName('DIV');
 for (i=0;i<p.length;i++) if (/post--\d+/.test(p[i].className)) p[i].style.background = 'red';
});

I wrap the code with a jQuery Document ready event so the code executes once the DOM is loaded.

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 21st 2014, 6:12 am

Yes, thank you! This is what I've been trying to do but I guess I had the syntax slightly off. I do have one question though if you don't mind. If I'm altering the innerhtml of certain blocks, is there any way to add stuff like spoilers/etc to it? The code I have now is


Code:
$(function() {
var num = document.getElementById('NUM').innerHTML;
var det = "[spoiler]" + num + "[/spoiler]";
document.getElementById('NUM').innerHTML = det;
})

This runs fine and replaces any html with the id 'NUM' with the string described by det. However it enters the words [ spoiler ] and [ / spoiler ] rather then actual spoilers.

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ange Tuteur on September 21st 2014, 4:39 pm

The bbcodes ([ spoiler ]) are parsed server side, so you'll have to insert HTML instead. I'm not sure how it'll work as I've never tried it, but here's the HTML for the spoiler from phpbb3 :
Code:
<dl class="codebox spoiler"><dt style="cursor: pointer;">Spoiler title :</dt><dd><div class="spoiler_content">Spoiler content</div></dd></dl>

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by bmbmjmdm on September 21st 2014, 6:14 pm

Thank you; this works! This solves all my problems, so the topic can be closed. Very Happy Razz Very good

bmbmjmdm
Forumember

Posts : 52
Reputation : 1
Language : English

Back to top Go down

Solved Re: Using Javascript in Forumotion

Post by Ange Tuteur on September 22nd 2014, 4:46 am

You're welcome Smile

Topic archived

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.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