473,770 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help changing DIV content - want to put a javascript into the DIV

Hi,

I Need help changing the content of a DIV. I sincerely researched the
issue and have not found a solution except to scrap the idea and stick
with the iframe code that I had been using. My purpose here is to
avoid iframes.

I know how to change the DIV content to other basic html statements,
such as basic IMG's or Lists, but I want to put a Javascript into the
DIV, and have not found a way to do it.

The Javascript that I want to place into the DIV is a typical
tickerbox, and it is found at:
http://www.24fun.com/downloadcenter/...xtbgfader.html

I saved the code for the tickerbox to a "tickerbox. js" file.

The relevant code:

(in Head...)

..box2 {width: 408px; height:88px;}

<script>
function jumptodiv() {
document.getEle mentById("area2 ").innerHTM L = ????
}
</script>
(Body...)

<DIV id="area2" style="box2">
<img src="someintrod uctionphoto.jpg ">
<!-- the goal is to replace this photo with the Tickerbox
Javascript when user clicks the button below -->

</div>

<form>
<input type="button" value="About" onClick="jumpto div()">
</form>

A working solution will be sincerely appreciated. (As a sidenote, I
cannot seem to get ANY javascript to work properly when "poked" into
the DIV. Even a plain alert statement will render, but will then give
an error.)

Jul 23 '05 #1
2 5259
rp***@my-deja.com wrote:
Hi,

I Need help changing the content of a DIV. I sincerely researched the
issue and have not found a solution except to scrap the idea and stick
with the iframe code that I had been using. My purpose here is to
avoid iframes.

I know how to change the DIV content to other basic html statements,
such as basic IMG's or Lists, but I want to put a Javascript into the
DIV, and have not found a way to do it.
You insert script elements just like any other element: create it, set
the attribute you want and then append it to some existing element.

e.g. create a file 'hi.js' with content:

alert('Hi');

Put the following HTML into a .html file in the same directory:

<input type="button" value="Insert script" onclick="
var d = document.getEle mentById('divA' );

var s = document.create Element('SCRIPT ');
s.type = 'text/javascript';
s.src = 'hi.js';
d.appendChild(s );
">
<div id="divA"></div>

When you click the button, the script element is appended to the div
element and the script runs.

The Javascript that I want to place into the DIV is a typical
tickerbox, and it is found at:
http://www.24fun.com/downloadcenter/...xtbgfader.html
Sorry, can't access the site from where I am. Over to you.

I saved the code for the tickerbox to a "tickerbox. js" file.

The relevant code:

(in Head...)

.box2 {width: 408px; height:88px;}

<script>
function jumptodiv() {
document.getEle mentById("area2 ").innerHTM L = ????
Using the above example, something like:

var d = document.getEle mentById('area2 ');

// Delete content:
var c;
while ( ( c = d.firstChild ) ) {
d.removeChild(c );
}

// Add the script element
var s = document.create Element('SCRIPT ');
s.type = 'text/javascript';
s.src = 'tickerbox.js';
d.appendChild(s );

should do the trick. The "Delete content" loop could be replaced by:

d.innerHTML = '';

but that is likely abhorrent to DOM evangelists. Since you need to use
DOM anyway you may as well stick to that and not introduce non-standard
methods when standards can be followed without inconvenience.
}
</script>
[...]
A working solution will be sincerely appreciated. (As a sidenote, I
cannot seem to get ANY javascript to work properly when "poked" into
the DIV. Even a plain alert statement will render, but will then give
an error.)


If you are attempting to insert the script using innerHTML, then that
is likely your problem. innerHTML is not part of any W3C standard, it
was invented by Microsoft and has been widely copied by browser
developers. Its behaviour is (as far as I know) 'reverse engineered'
and therefore essentially undocumented and unspecified, though
Microsoft provide some documentation on its use:

<URL:http://msdn.microsoft. com/workshop/author/dhtml/reference/properties/innerhtml.asp>

It is very useful in some situations, but use it with caution.
--
Rob
Jul 23 '05 #2

Hi Rob,

Thanks. Awesome information, much appreciated. Exactly what I needed.

Jul 23 '05 #3

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

Similar topics

10
63611
by: Free-Ed, Ltd. | last post by:
I am going nuts trying to find a paragraph in a book that described how to change the text content (HTML) in a DIV. Actually I have an array of HTML strings that I want to drop into the DIV, depending on button clicks, etc. Putting this stuff into TEXTAREA and TEXT is simple, but I want to be able to mix font families, weights, sizes, and stuff like that. Thanks for your help.
7
8695
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong, somehow I always end up with error messages and functions not working right. Can someone please help me? I have a form, inside is 1 Text Field and 2 Password Fields. What I'm looking to do is: - Make sure password fields are equal - Set...
55
7308
by: Ton den Hartog | last post by:
Stupid basic question but I find it horribly imposible to find the answer elsewhere... :-( I want to have a piece of text in my HTML page and want to be able to change it in a Javascript function that is called from a button. I think I can use a <div id="t"></div> for this ? Something like
3
5976
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change the value of that session cookie in response to a button click in a form, without resubmitting the page. For some reason, the following doesn't seem to work:
2
1744
by: Dominic Myers | last post by:
Hi there, wondered if someone could point me to an appropriate tutorial or offer advice on the following problem? I've got a web page which uses lots of divs to position the content of the page and I'm using a nice javascript to alter the css of a table of links. The thing is I don't want the table of links to point to an external site but to calla function which will replace the content of a layer... perhaps it's be better if I...
31
5723
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a calendar, 7 across by whatever needed down, and I manually create it each month - not a big deal. Every day I go in and darken the background color of the current day's cell by changing the appropriate <TD> entry to <TD bgcolor="c63800"> and...
6
2045
by: tshad | last post by:
Is there a way during Page_Load to change or add an attribute to the Body tag? I want to be able to change the onLoad body attribute to do a focus on one of my text boxes, such as: onLoad="document.forms.txtLogon.focus();" The problem is I have my <body> in an include file and want to set the onLoad attribute during Page_Load time.
0
5576
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
2
3156
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.