473,406 Members | 2,843 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,406 software developers and data experts.

Add content to existing div

I have been trying to find an example of how-to add html text to an
exisiting div and have had little success.

The best I found so far was

var pTag = document.createElement("p");
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById("FormErrors").appendChild( pTag);

However, I was hoping I could pass HTML code and not just text,
something more like

"New line added.<br />"

or anyother HTML Tag I may need to use.

Also, the code only seems to work in IE and not Firefox...?

Thank you for your help!

QB
Sep 4 '08 #1
7 1958
Assuming your div has an id attribute called "div_id", you can do
this:

var div = document.getElementById('div_id');
div.innerHTML = "<p><b>Whatever</bHTML that you may want.</p>";

-Jeff

On Sep 4, 9:54*am, question....@hotmail.com wrote:
I have been trying to find an example of how-to add html text to an
exisiting div and have had little success.

The best I found so far was

var pTag = document.createElement("p");
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById("FormErrors").appendChild( pTag);

However, I was hoping I could pass HTML code and not just text,
something more like

"New line added.<br />"

or anyother HTML Tag I may need to use.

Also, the code only seems to work in IE and not Firefox...?

Thank you for your help!

QB
Sep 4 '08 #2
qu**********@hotmail.com writes:
I have been trying to find an example of how-to add html text to an
exisiting div and have had little success.

The best I found so far was

var pTag = document.createElement("p");
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById("FormErrors").appendChild( pTag);

However, I was hoping I could pass HTML code and not just text,
something more like

"New line added.<br />"

or anyother HTML Tag I may need to use.
You can.
Also, the code only seems to work in IE and not Firefox...?
Ther error is somewhere else. This should work in FF; most browsers
support innerHTML, even though it's not officially standard.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Sep 4 '08 #3
On Sep 4, 2:30*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
question....@hotmail.com writes:
I have been trying to find an example of how-to add html text to an
exisiting div and have had little success.
The best I found so far was
var pTag = document.createElement("p");
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById("FormErrors").appendChild( pTag);
However, I was hoping I could pass HTML code and not just text,
something more like
"New line added.<br />"
or anyother HTML Tag I may need to use.

You can.
Also, the code only seems to work in IE and not Firefox...?

Ther error is somewhere else. This should work in FF; most browsers
support innerHTML, even though it's not officially standard.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/- Hide quoted text -

- Show quoted text -

Here is the function in question. It works fine in IE but nothing in
Firefox.

function validate_form(theForm) {
/*Validates the user submitted data to ensure that data has been
input and that it is valid
and posts an error message if there is an issue.*/
var frmOk = true; //initialize validation status variable
var errColor = 'ffff99'; //background color when there is an error
in validation

// Create an array of controls to ensure that it wasn't left blank
var noBlanks = [ "FirstName", "LastName", "Address", "City",
"Province", "PostalCode", "TelResidential",
"TelBusiness", "TelCell", "Email", "Job"];

for ( i=0; i < noBlanks.length; i++ ){
if (isEmpty(document.getElementById(noBlanks[i]).value)) {

document.getElementById(noBlanks[i]).style.backgroundColor=errColor;

var pTag = document.createElement('p');
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById('FormErrors').appendChild( pTag);
frmOk = false;
}
}

if (frmOk == false) {
document.getElementById('FormErrors').style.displa y='block';
return false;
} else {
document.getElementById('FormErrors').style.displa y='none';
return true;
}
}

Any idea where I have made a mistake?

Thank you for your help,

QB
Sep 5 '08 #4
On Sep 4, 2:30*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
question....@hotmail.com writes:
I have been trying to find an example of how-to add html text to an
exisiting div and have had little success.
The best I found so far was
var pTag = document.createElement("p");
pTag.innerHTML = noBlanks[i]+" is a mandatory field.";
document.getElementById("FormErrors").appendChild( pTag);
However, I was hoping I could pass HTML code and not just text,
something more like
"New line added.<br />"
or anyother HTML Tag I may need to use.

You can.
Also, the code only seems to work in IE and not Firefox...?

Ther error is somewhere else. This should work in FF; most browsers
support innerHTML, even though it's not officially standard.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/- Hide quoted text -

- Show quoted text -
Might I ask you, what is officially the standard approach to doing
what I am wanting to do?
QB
Sep 5 '08 #5
qu**********@hotmail.com meinte:
Here is the function in question. It works fine in IE but nothing in
Firefox.

function validate_form(theForm) {
/*Validates the user submitted data to ensure that data has been
input and that it is valid
and posts an error message if there is an issue.*/
var frmOk = true; //initialize validation status variable
var errColor = 'ffff99'; //background color when there is an error
in validation

// Create an array of controls to ensure that it wasn't left blank
var noBlanks = [ "FirstName", "LastName", "Address", "City",
"Province", "PostalCode", "TelResidential",
"TelBusiness", "TelCell", "Email", "Job"];

for ( i=0; i < noBlanks.length; i++ ){
if (isEmpty(document.getElementById(noBlanks[i]).value)) {

document.getElementById(noBlanks[i]).style.backgroundColor=errColor;

Why gEBI? I suppose getElementsByName would be more appropriate. Due to
an "odd" implementation IE also populates the id property of elements
with names with the name value.

But it's IE only.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 5 '08 #6
qu**********@hotmail.com meinte:
On Sep 4, 2:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
>Ther error is somewhere else. This should work in FF; most browsers
support innerHTML, even though it's not officially standard.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/- Hide quoted text -

- Show quoted text -
Please don't quote signatures. And "- Show quoted text -". Get yourself
a decent newsreader like Thunderbird.
Might I ask you, what is officially the standard approach to doing
what I am wanting to do?
The usual methods for manipulating the DOM: createElement(),
append/replace/removeChild(), ...

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 5 '08 #7
qu**********@hotmail.com writes:
On Sep 4, 2:30Â*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
>Ther error is somewhere else. This should work in FF; most browsers
support innerHTML, even though it's not officially standard.

Might I ask you, what is officially the standard approach to doing
what I am wanting to do?
QB
The "official" approach would be to generate each element, including
the TextNodes using the DOM API:

http://www.w3.org/TR/REC-DOM-Level-1...e-binding.html

Note that this can be significantly slower than using innerHTML in
some implementations if you're using many elements.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Sep 5 '08 #8

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

Similar topics

12
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a...
0
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress...
0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
38
by: Emmett | last post by:
I have a simple jacascript that randomizes the background of the top frame of my webpage http://www.duke.edu/~efn. For some reason, my Internet Explorer started blocking the background and...
1
by: Epetruk | last post by:
Hello all, I'm sorry for the long post, but I think it's better if I'm as detailed as I can be so that I don't make a mistake in my choice and so that there's a clear understanding of to what...
0
by: Garrek | last post by:
I have an existing ASP.Net application that must be modified to support mixed content: Latin-based languages (i.e. English) intermixed with Arabic. Our code and database assumes everything is...
4
by: rachel | last post by:
Hello, I am currently contracted out by a real estate agent. He has a page that he has created himself that has a list of homes.. their images and data in html format. He wants me to take...
3
by: Tom | last post by:
Hi, I am currently looking for a Content Management System for one of my project in ASP.NET. Here are the requirements: * web based content management * ability to enter content/fragment...
0
by: alexsink | last post by:
I am trying to get apache content negotiation to redirect only zh-CN(mainland China, where Simplified Chinese translations are available) language types to Chinese web pages, and have all other...
0
by: Nigel Norman | last post by:
Although I have written some perl ,I have obviously missed something. I have created a database for my local tennis club, which can be updated etc etc. I thought it would be a good idea to for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.