473,786 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting innerHTML

Hey,

I have a DIV and I want to dynamically set its innerHTML. I know I can
set it by doing the following myDiv.innerHTML = '<img
src=\"myImage.g if\">'
However, the html that I want to set in it is quite large so I dont
want to have to hard code the HTML like I just did.
My question is....is it possible to assign an existing html page to the
innerHTML.
e.g. myDiv.innerHTML = 'mytest.html'
So that the contents of the mytest.html would be set in myDiv's
innerHTML.

Thanks,

Chris

Jun 6 '06 #1
22 2378
Chris Moltisanti wrote:
Hey,

I have a DIV and I want to dynamically set its innerHTML. I know I can
set it by doing the following myDiv.innerHTML = '<img
src=\"myImage.g if\">'
However, the html that I want to set in it is quite large so I dont
want to have to hard code the HTML like I just did.
My question is....is it possible to assign an existing html page to the
innerHTML.
Sort of.
e.g. myDiv.innerHTML = 'mytest.html'
That would set the innerHTML to, literally, 'mytest.html'
So that the contents of the mytest.html would be set in myDiv's
innerHTML.


XMLHttpRequest (aka AJAX) - call the page, get back the response string,
apply the response string to the myDiv.innerHTML
Jun 6 '06 #2
Thanks for the reply.

I have use AJAX a little bit, bu I am unfamiliar with calling a pag
with AJAX. Any ideas on the syntax to do this?
I thought AJAX was more for making server calls.......

Chris.

Jun 6 '06 #3
Chris Moltisanti wrote on 06 jun 2006 in comp.lang.javas cript:
Thanks for the reply.


What reply?

Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers.

<http://www.safalra.com/special/googlegroupsrep ly/>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 6 '06 #4
The previous post is not related to javascript so please ignore it.
My question again is how can I get an animated GIF to continue
animating while some javascript processing is bien executed.

Thanks

Chris

Jun 6 '06 #5
The previous post is an annoyance and unrelated to javascript. Please
ignore it.
My question again........ho w do I call a page using AJAX? Is AJAX not
ususally used for server calls?

Thanks

Chris

Jun 6 '06 #6
Ivo
"Chris Moltisanti" wrote
The previous post is an annoyance and unrelated to javascript. Please
ignore it.
My question again........ho w do I call a page using AJAX? Is AJAX not
ususally used for server calls?


What previous post? You didn't quote it, which is a very simple thing to do,
which is one of the reasons why quoting previous posts has become such a
common thing on Usenet. The other reason is of course that it is nothing but
sensible to quote what you are replying to. I 'd like to be able to judge
for myself whether or not it is related to javascript, not because I don't
trust your judgement, but just because I 'd like to help take the discussion
further. And how can I discuss what I haven't read?

As to the thoughts on AJAX: I believe if I make an AJAX call, it is by
definition to a server. If the URL used is (also) meant to be accessed
through a regular HTTP connection and viewed in a browser on its own, you
might indeed say I am calling "a page" using AJAX, but the word game has
little significance. Whatever the server responds with is either a string of
text (possibly containing HTML tags or other code) or an XML object to the
receiving javascript, and is to be treated as such within the original page.

hth
ivo
http://www.yorick.onlyfools.com/
Jun 6 '06 #7
On Tue, 06 Jun 2006 14:27:59 -0700, Chris Moltisanti wrote:
Thanks for the reply.

I have use AJAX a little bit, bu I am unfamiliar with calling a pag
with AJAX. Any ideas on the syntax to do this?
I thought AJAX was more for making server calls.......


I've just been doing something like this using dojo (www.dojotoolkit.org),
which makes it pretty easy:

function infoPage(url,ca llback) {
// the url to load.
this.url=url;
// is the file loaded and parsed?
this.ready= false;
// did the loading fail?
this.fail=false ;
// reference to a div with the page in it.
this.infoNode=n ull;
// callback for when the html has loaded.
this.callback=c allback;
this.load= function() {
// load the data file.
var bindArgs = {
url: this.url,
mimetype: "text/html",
error: dojo.lang.hitch (this,"loadErro r"),
load: dojo.lang.hitch (this,"loaded")
};
var requestObj = dojo.io.bind(bi ndArgs);
};
this.loaded=fun ction(type, data, evt){
// handle successful response here
// parse HTML into DOM nodes.
var newNodes=dojo.h tml.createNodes FromText(data,t rue);
this.infoNode=n ewNodes[0];
// callback which does any further processing - e.g. inserting the node
in the document.
this.ready=true ;
this.callback(t his);
};
this.loadError= function(type, errObj){
// handle error here
this.fail=true;
alert("Failed to load page");
}
}

If you don't like toolkits, you'll probably have to write your own
javascript to parse html into DOM nodes, or else use innerHTML.

Jun 7 '06 #8
Another more simplistic option would be to have your javascript merely
use document.create Element to create an iframe, set the iframes src to
whatever page you want the div to contain and then appendChild on the
div. Maybe not as clever or web2.0'ish enough for you, but it
definitely will get the job done in the least amount of code.

-E

andy baxter wrote:
On Tue, 06 Jun 2006 14:27:59 -0700, Chris Moltisanti wrote:
Thanks for the reply.

I have use AJAX a little bit, bu I am unfamiliar with calling a pag
with AJAX. Any ideas on the syntax to do this?
I thought AJAX was more for making server calls.......


I've just been doing something like this using dojo (www.dojotoolkit.org),
which makes it pretty easy:

function infoPage(url,ca llback) {
// the url to load.
this.url=url;
// is the file loaded and parsed?
this.ready= false;
// did the loading fail?
this.fail=false ;
// reference to a div with the page in it.
this.infoNode=n ull;
// callback for when the html has loaded.
this.callback=c allback;
this.load= function() {
// load the data file.
var bindArgs = {
url: this.url,
mimetype: "text/html",
error: dojo.lang.hitch (this,"loadErro r"),
load: dojo.lang.hitch (this,"loaded")
};
var requestObj = dojo.io.bind(bi ndArgs);
};
this.loaded=fun ction(type, data, evt){
// handle successful response here
// parse HTML into DOM nodes.
var newNodes=dojo.h tml.createNodes FromText(data,t rue);
this.infoNode=n ewNodes[0];
// callback which does any further processing - e.g. inserting the node
in the document.
this.ready=true ;
this.callback(t his);
};
this.loadError= function(type, errObj){
// handle error here
this.fail=true;
alert("Failed to load page");
}
}

If you don't like toolkits, you'll probably have to write your own
javascript to parse html into DOM nodes, or else use innerHTML.


Jun 7 '06 #9
On Wed, 07 Jun 2006 01:36:29 -0700, Eric Ryan Harrison wrote:
Another more simplistic option would be to have your javascript merely
use document.create Element to create an iframe, set the iframes src to
whatever page you want the div to contain and then appendChild on the
div. Maybe not as clever or web2.0'ish enough for you, but it
definitely will get the job done in the least amount of code.

-E


I tried this way first, but I didn't like the iframe - you have to set a
fixed height window with a scrollbar and it looked ugly in my layout.
Jun 7 '06 #10

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

Similar topics

4
47584
by: Kerri | last post by:
Hi, I have a span as below. <span id="lblTest" style="color:#FF0033;font- weight:bold;">This is a test.</span> When the user clicks a checkbox I call below code to set my span text to blank.
2
3569
by: Kerri | last post by:
Sorry, That was a typo. It should read. I have a RequiredFieldValidator This gets rendered out as a <span> I want to set the innerHTML.
7
4898
by: Harag | last post by:
Hi all I think this is in the wrong group but since I don't read others much or code in java script I was wondering if anyone could help me with this small problem, as I code mostly in ASP vbscript. I have the following piece of Javascript client code that displays the users clock on the browser and updates it every second.
5
21634
by: Soren Vejrum | last post by:
I am working on a web-based html editor using MSIE's designmode and iframes. Everything works just fine, but MSIE changes all my relative "a href" and "img src" links (i.e. "/index.asp") to absolute links (i.e. "http://localhost/index.asp") when I set the iframe's innerHTML. This is bad as the links are supposed to be relative. How can I avoid this? Any solutions/suggestions are much appreciated.
7
4868
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh'; this.iframe.style.display = 'none';
10
1785
by: johndoe | last post by:
While creating a shopping cart application I noticed a strange bug which resulted in the Constructor and everything being called twice. I was using Inherited classes ClassShowProducts inherited TemplatePage which inherited System.Web.UI.Page which I thought was the problem so I spent all day recoding everything so that ClassShowProducts was inherited from System.Web.UI.Page. Then I found out that it still happend. I then quickly narrowed it...
5
1383
by: verrice | last post by:
Hello, I'm writing a web application where I want to load bits of data at runtime from the client end (via AJAX). The loading of the data part works great, but for some reason anytime I try to impart a style setting (via either putting it inline, a CSS, or through javascript) the DIV completely ignores my setting. The setting most importantly I'm trying to apply is display: none, but none of them work. If I pre-create everything...
1
2244
by: robbiedoo | last post by:
How can a value be set to a label in javascript. I can set values to <h6> tags, but I need to set the value of a label. Particularly becasue I can't seem to acces the value of an <h6> tag in the aspx.vb code-behind on the aspx page. So far I got the changing of <h6> values working by doing this: function SellLots_DoFSCommand(command, args){ if(args != "" && args != null) { ...
8
10109
Toxinhead
by: Toxinhead | last post by:
Hey there guys I am having a little trouble with InnerHTML as i can't seem to figure out how to set the style of my div tag..... What im trying to do is that when i rollover pic1 it changes that pic and displays:block and visiblity:visible....and also changes pic2.. When the webpage is loaded it displays:none and visivlity:hidden also Heres my code:
0
9647
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
9496
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
10363
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
10164
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
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.