473,409 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

how can I get plain text assigned through innerHTML to work as real Javascript? Should I use eval()?


I'm helping to build a site where people recovering from addiction are
suppose to able to share their stories with each other, and encourage
each other toward greater sobriety. One idea that the client had was a
"Sharing Wall" where the posts fade in and fade out and are
constantly replaced. This was suppose to be achieved through Ajax. If
people don't have Javascript on, then they simply read the first 6
posts which appear on the front of the site. But if Javascript is on,
then every 20 seconds each of 6 posts gets updated. You can get a
sense of the front page here:

http://www.bluewalldev.com/secondroad/index.php

The site is still quite rough. The designer is working on it right
now, so things might be crazy when you look at it.

For my part, I'm using the Prototype library to make calls against
this page:

http://www.bluewalldev.com/secondroa...php?choiceMade[]=showRandomCommunityPost

Hit refresh on that page a few times. You'll see it serves a different
post each time.

Here is my problem. Prototype fetches text and assigns it using
innerHTML. The text I'm fetching contains Javascript. Is there any
easy way to bring this Javascript to life? Perhaps using eval()?

Is there any easy way to turn text into elements that belong to the
DOM?

I'm normally comfortable building new elements to a page using DOM
friendly methods, but in this case, I can't think how to get this
information from the database and wrap it in HTML and Javascript in a
way that doesn't simply kill performance.

I suppose I could try to fetch the needed info as XML, but it seems
like it would be an amazing amount of work to turn that XML into the
HTML and Javascript that one sees on this page.

Any suggestions?

Sep 9 '07 #1
2 3537
Jake Barnes said the following on 9/8/2007 11:02 PM:
I'm helping to build a site where people recovering from addiction are
suppose to able to share their stories with each other, and encourage
each other toward greater sobriety. One idea that the client had was a
"Sharing Wall" where the posts fade in and fade out and are
constantly replaced. This was suppose to be achieved through Ajax.
The main source of your problem is in not designing the back-end to be
Ajax ready. Your first step should be to correct the script errors on
the main page.

If people don't have Javascript on, then they simply read the first 6
posts which appear on the front of the site. But if Javascript is on,
then every 20 seconds each of 6 posts gets updated. You can get a
sense of the front page here:
http://www.bluewalldev.com/secondroad/index.php
Along with the script errors?
The site is still quite rough. The designer is working on it right
now, so things might be crazy when you look at it.

For my part, I'm using the Prototype library to make calls against
this page:

http://www.bluewalldev.com/secondroa...php?choiceMade[]=showRandomCommunityPost

Hit refresh on that page a few times. You'll see it serves a different
post each time.
I got the same post 3 times in a row. Not many posts yet?
Here is my problem. Prototype fetches text and assigns it using
innerHTML. The text I'm fetching contains Javascript. Is there any
easy way to bring this Javascript to life? Perhaps using eval()?
Not even using eval will get that part of the script to execute as it
isn't a script block. The only scripting I see in your random posts page
are onmouseover and onmouseout event handlers.
Is there any easy way to turn text into elements that belong to the
DOM?
The simplest way to fix your particular problem is going to be to assign
the onmouseover and onmouseout using script, put that script in a script
block and then get that script block executed. Once you have your script
in script blocks instead of the HTML code, try this thread and the links
in it:

<URL:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/7120355459a853f1/5cd52d6b2ad4db40?lnk=gst&q=js+execute+inject&rnum= 1#5cd52d6b2ad4db40>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 9 '07 #2
On Sep 9, 1:21 am, Randy Webb <HikksNotAtH...@aol.comwrote:
Jake Barnes said the following on 9/8/2007 11:02 PM:
I'm helping to build a site where people recovering from addiction are
suppose to able to share their stories with each other, and encourage
each other toward greater sobriety. One idea that the client had was a
"Sharing Wall" where the posts fade in and fade out and are
constantly replaced. This was suppose to be achieved through Ajax.

The main source of your problem is in not designing the back-end to be
Ajax ready. Your first step should be to correct the script errors on
the main page.
I'm confused by your reference to script errors. There are no errors
on the page, save for the errors produced by the question that I am
here raising. If there were no errors, then I would not be posting to
comp.lang.javascript. But I'm not aware of any errors, aside from the
one that I'm here asking about.

If people don't have Javascript on, then they simply read the first 6
posts which appear on the front of the site. But if Javascript is on,
then every 20 seconds each of 6 posts gets updated. You can get a
sense of the front page here:
http://www.bluewalldev.com/secondroad/index.php

Along with the script errors?
Well, I'm asking how to fix those errors. Those errors occur because
the inline Javascript is not being read as Javascript once Prototype
fetches the text and assigns it to innerHTML.

The site is still quite rough. The designer is working on it right
now, so things might be crazy when you look at it.
For my part, I'm using the Prototype library to make calls against
this page:
http://www.bluewalldev.com/secondroa...php?choiceMade[]=showRandomCommunityPost
Hit refresh on that page a few times. You'll see it serves a different
post each time.

I got the same post 3 times in a row. Not many posts yet?
Myself and the client typed in about 20 posts so we'd have some sample
text to work with. So, yes, with 6 posts appearing at a time, the
chance for overlap is large. Later this week I'll be altering the PHP
code so that the id for each currently showing post is stored in the
$_SESSION variable, and that information will be used to foreclude
repeats. But I'd like first to get the Javascript working right.

Here is my problem. Prototype fetches text and assigns it using
innerHTML. The text I'm fetching contains Javascript. Is there any
The simplest way to fix your particular problem is going to be to assign
the onmouseover and onmouseout using script, put that script in a script
block and then get that script block executed. Once you have your script
in script blocks instead of the HTML code, try this thread and the links
in it:

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread...>
Thanks much for the tip.

Assuming I instead decide to fetch the data as XML and transform it
using DOM friendly methods, do you have a link you'd like to share
regarding easy XML to DOM transitions?

Sep 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
4
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document...
28
by: Randy Starkey | last post by:
Hi, Does anyone know where I can get a script that show a little plus sign after a line of text, that when you click the plus sign, more text is revealed on that same page, like a continuing...
14
by: Stefan Mueller | last post by:
With the following code I can add a new row to an existing table. That really works great. Many thanks to all who helped me so far. But my problem is that the added cells do somehow not have the...
10
by: Jake Barnes | last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page where I could experiment. The idea of this page is that you click in one of the boxes to get some controls, at which point you can...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
15
by: rage3324 | last post by:
I am posting html onto my main page between div tags using xmlhttprequest and innerhtml. The html I am posting has javascript inside which I am executing using the eval() function. However, the...
8
by: sneddo | last post by:
Ok I am trying to do the above, I have got a script that will restrict the length but it requires the user to enter the field and hit a key, before it will work. This would normaly be find, but...
6
by: Flyzone | last post by:
Hello, i'm trying to paste copied text from word into an input box. This text is saved into a oracle db and then used as text in another javascript. The problem is that using the saved text...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.