Using data in a script

13 posts by 3 authors in: Forums > CMS Builder
Last Post: August 5, 2009   (RSS)

By Roj - July 31, 2009

Hi,

I am creating a website where I have 6 images and when I mouse over each image it changes the text on the page.
I have this working using a small script but when I replace the 6 pieces of text with the code to get the data from CMS Builder nothing works. No sure if I can use php in javascript. perhaps this is the problem.

Any ideas on how I can get this to work? Here's the web page http://waittandco.sc14.co.uk/
Roj

Re: [Roj] Using data in a script

By Dave - July 31, 2009

Hi Roj,

The quickest way to resolve javascript issues is to:
a) Save the page as html
b) Open it in your browser and look at your javascript error console
c) Figure out where the errors are in the html version, then update the PHP version to match.

One thing I saw was this:
onover('<p><strong>English ... pede.</p>')">

You need quotes (which I added in red) around the value you pass to the onover() javascript function.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Using data in a script

By Roj - August 1, 2009

Hi Dave,

Thanks for your reply.
I have tried this with the quotes but it still does not work.
If I use normal text the script works onmouseover="onover('here is some text')"
When I replace the text it does not work onmouseover="onover('<?php echo $home_pageRecord['english_text'] ?>')"

here is the script

function onover(what){
document.getElementById('maintext').innerHTML=''+what+'';
}

Any ideas?

Roj
Roj

Re: [Roj] Using data in a script

By Roj - August 1, 2009

Hi Dave,

I have got this working by changing the field type from wysiwyg to text box. but I can not add any formating.
If I add and html ie <br/> it stops working.

Any ideas?

Roj
Roj

Re: [Roj] Using data in a script

By Roj - August 2, 2009

Hi Dave,

I have got this working now except when I use </p><p> in the text.

Using the wysiwyg editor in CMS Builder, when you add a carriage return it creates white space between </p> and <p> which causes it not to work. If I use <br /><br /> it all works fine.
See http://waittandco.sc14.co.uk/index.html The second flag, (the French one) uses </p><p> as does not work, all other flags use <br /><br /> and work OK.

Regards

Roj
Roj

Re: [Roj] Using data in a script

By ross - August 3, 2009

Hi Roj

Thanks for the update!

Glad to see you kept the ball rolling. With the <p> tags, there are going to be a couple different options.

One, you could use some CSS to change how <p> tags work. How comfortable are you working with HTML and CSS?

The second option would be to use some PHP to replace the <p> tags in your CMS Builder content with <br> tags. How comfortable are you working with PHP.

I can walk you through either option so just let me know which one you like the sounds of and we'll go from there.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [Roj] Using data in a script

By Dave - August 3, 2009

Hi Roj,

I think it's the enters and the single quotes that are causing problems. Try this (new code in red):

...onover('<?php echo addcslashes($record['yourFieldName'], "\\'\\\"\n\r") ?>')">

What the addcslashes($variable, "\\'\\\"\n\r") does is add a backslash before ' and " and shows enters as \n which javascript understands as a enter (also called nextline).

Let me know if that works for you. If not attach your viewer file and post an url to the page and we'll take a look.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Using data in a script

By Roj - August 4, 2009

Hi Dave,

By using the addcslashes the following tags now work
<p> <hr>

Still have problems with underline, images and hyperlinks.
Do you think it would be possible to use some php script instead of javascript?

Roj
Roj

Re: [Roj] Using data in a script

By Dave - August 4, 2009

Hmmm, ok. Can you attach your viewer file and post an url to the page again and we'll take a look?

It's not possible to do without javascript, but shouldn't take much more.
Dave Edis - Senior Developer
interactivetools.com