Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-05-17 01:42:19
- shilmy
- Member
- Registered: 2006-04-29
- Posts: 49
Javascript in article body, is it possible?
I’d like to insert a Javascript code in article body, is it possible? How?
Regards,
Sjarief
Offline
#2 2006-05-17 02:00:18
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Javascript in article body, is it possible?
How much JavaScript and what’s the purpose? (That determines the best way to go about this.)
Offline
#3 2006-05-17 02:44:54
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Offline
#4 2006-05-17 03:09:57
- shilmy
- Member
- Registered: 2006-04-29
- Posts: 49
Re: Javascript in article body, is it possible?
I’m thinking of putting chitika’s eMiniMalls Code. The reason I want to put it in article bodies, not in the template, is I want match the ad with the article.
For example, if my article is about “bamboo flooring”, I want to put ads about bamboo flooring when the article is displayed.
Offline
#5 2006-05-17 06:19:06
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Javascript in article body, is it possible?
Okay, yes you can do this, you’ll put your JavaScript in your article form. If you can show the JavaScript you want to use, someone can walk you through it.
Offline
#6 2006-05-18 23:26:55
- shilmy
- Member
- Registered: 2006-04-29
- Posts: 49
Re: Javascript in article body, is it possible?
Thanks for the hints, the keyword is “form”. I ‘ve included the javascript in the article using form.
I just wish there are easier solution since this script is only used in one article. Other articles will need their own scripts, thus will need another forms.
Offline
#7 2006-05-19 01:07:33
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: Javascript in article body, is it possible?
It sounds like you ought to be generating or passing information to your javascript, rather than having a separate script for each article.
Alex
Offline
#8 2006-05-19 02:07:02
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Javascript in article body, is it possible?
It sounds like you ought to be generating or passing information to your javascript, rather than having a separate script for each article.
Yes, exactly. Can you show us what your JavaScript currently is? then we can show you how to just set it up once, not for every article.
Offline
#9 2006-05-19 16:36:19
- shilmy
- Member
- Registered: 2006-04-29
- Posts: 49
Re: Javascript in article body, is it possible?
Hey, that’s really good idea. I wonder why I didn’t think about it.
Ok here is the javascript code:
<code>
<script type=“text/javascript”><!—
ch_client = “xxxxx”;
ch_width = 300;
ch_height = 250;
ch_non_contextual = 1;
ch_nosearch = 1 ;
var ch_queries = new Array( “bamboo flooring” );
var ch_selected=Math.floor((Math.random()*ch_queries.length));
ch_query = ch_queries[ch_selected];
//—></script>
<script src=“http://scripts.chitika.net/eminimalls/mm.js” type=“text/javascript”>
</script>
</code>
What I need is to change “bamboo flooring”(line 7) to keyword related to each articles.
So how to pass that info from articles to javascript?
Offline
#10 2006-05-20 01:02:44
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Javascript in article body, is it possible?
Go to the advanced section of your admin prefs, and create a custom field named “eMiniMalls”. If you now look in your “write” tab on the left-hand side, you’ll see a new textbox named “eMiniMalls”, here you’d enter, as per your example: bamboo flooring
.
Lastly, add the following to your article form:
<txp:if_custom_field name="eMiniMalls"><script type="text/javascript"><!--
var ch_client = 'xxxxx';
var ch_width = 300;
var ch_height = 250;
var ch_non_contextual = 1;
var ch_nosearch = 1;
var ch_selected = Math.floor((Math.random() * ch_queries.length));
var ch_queries = new Array("<txp:custom_field name="eMiniMalls" />");
var ch_query = ch_queries[ch_selected];
//--></script>
<script type="text/javascript" src="http://scripts.chitika.net/eminimalls/mm.js"></script></txp:if_custom_field>
:)
Offline
#11 2006-05-20 07:10:29
- shilmy
- Member
- Registered: 2006-04-29
- Posts: 49
Re: Javascript in article body, is it possible?
Hi thanks, really neat and simple solution. It already spark another idea in my head for my site.
I guess the same solution can be applied to php code.
You guys really great. Thanks again.
Regards,
Sjarief
Offline