Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 12th, 2002, 11:58 AM
baddogg99 baddogg99 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
innerHTML question

I recently read the "Building a WYSIWYG" article and thought it was GREAT!

However, I am stuck with one question that I cannot find an answer to.

Using the wysiwyg to create content is fine and easy, however, what if I want to pull the saved content from the database and re-populate the WYSIWYG so I can update the content?

Specifically, I have been unable to populate the Iframe's innerHTML with the HTML that was saved in the database.

Any help is appreciated!

Brant

Reply With Quote
  #2  
Old November 12th, 2002, 07:01 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
can't you just do something like this

<script>
function populate() {
object.innerHTML = <%= rs.getString(2)%>
}
</script>

if you don't understand this then post back and I'll explain, I've tried too explain it, but maybe you'll just get it?

It may help if you say what language you are using. that is the JSP way of doing it.

Reply With Quote
  #3  
Old November 13th, 2002, 08:50 AM
baddogg99 baddogg99 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Right, but...

I guess I didn't explain well enough.

You are right with your explanation, thank you. I can get that to work.. no problem.

My problem is when the page loads, I cannot make an "onLoad" that can take the content I am providing and prepopulate the iFrame.

Here is the function I created (Cold Fusion, BTW):

Code:
function addContent() {
var contents = "#attributes.content#";
iView.document.body.innerHTML = contents;
}


(iView is the name of the iFrame)

If I make a button that has onClick=addContent(), it works great.

However, I need an onload=addContent() that will populate the iframe when the page loads. When I do this, I get the following error:

Code:
'iView.document.body' is null or not an object.


Any ideas?

Reply With Quote
  #4  
Old November 13th, 2002, 07:29 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
try this

Code:
<script>
var iViewContentLoaded = false;

function addContent() {
  // Check to see if content has been loaded
  if(!iViewContentLoaded) {
    // Check to see if there is an iView.document.body object
    if(iView.document.body) {
      // The object exists so populate it
      var contents = "#attributes.content#";
      iView.document.body.innerHTML = contents;
      iViewContentLoaded = true;
    } else {
       // The object doesn't exist yet, so we'll try again in 2 seconds
       setTimeout("addContent()", 2000);
    } 
  }
}
</script>


Because you said it works when you click a button, it seems that onLoad, is doing its thing before the iFrame has been created.

This code is self explainetory, but if you need clarification then ask.

Reply With Quote
  #5  
Old November 14th, 2002, 08:08 AM
baddogg99 baddogg99 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That worked!

Thanks so much for all your help! That worked perfectly!

Reply With Quote
  #6  
Old November 14th, 2002, 06:00 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
"One is always glad to be of service"

Reply With Quote
  #7  
Old November 15th, 2002, 09:44 AM
baddogg99 baddogg99 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ONE more question...

Ok, now I understand how to use the innerHTML, outerHTML features. Now I am wondering this...

I made a colorpicker that allows the user to change the background color of the entire iframe. It works ok, when the user saves the content, it saves the <body bgcolor="#ffcc00"> tag as part of the content. I used the outerHTML to do this. This works good.

Now, I want to pull this content out of the database, and put the content back in the iframe for editing.... which you showed me how to do. In fact, it works perfectly EXCEPT... the background color <body> defaults to white in the iframe, even though the body tag says it is another color.

HOW do I pull the color out of the body tag and use it to change the background of the iframe?

Thanks for the help!

Reply With Quote
  #8  
Old November 17th, 2002, 08:52 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I've had a go at this but I can't figure it out. sorry.
But with the code above:
I was using the code above and noticed a flaw in my logic, if you step through the code abpve you'll realise I test to see if the object is loaded twice (indirectly) but it is overhead that isn't needed so to fix it use this
Code:
<script>
function addContent() {
  // Check to see if there is an iView.document.body object
  if(iView.document.body) {
    // The object exists so populate it
    var contents = "#attributes.content#";
    iView.document.body.innerHTML = contents;
  } else {
     // The object doesn't exist yet, so we'll try again in 2 seconds
     setTimeout("addContent()", 2000);
  } 
}
</script>

Reply With Quote
  #9  
Old May 22nd, 2003, 04:25 AM
MstrDavid MstrDavid is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 MstrDavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
innerHTML with onload and timeout

Having the same problem I tried this sollution, however I keep getting an error when the function fires for the second time.

var iViewContentLoaded = false;
function populate()
{
if(!iViewContentLoaded)
{
if(iView.document.body)
{
// The object exists so populate it
var contents = 'some stuff';
iView.document.body.innerHTML = contents;
iViewContentLoaded = true;
}
else
{
// The object doesn't exist yet, so we'll try again in 2 seconds
setTimeout("addContent()", 2000);
}
}
}

With onload the time out is triggered and the page reads done. After two seconds it reads error on page:
Error: Object expected

I tried putting a prompt in there, and if the prompt is situated before the if loop, as in, prompt, then execute if statement the function works, but without the promt, even with the timeout function the error keeps occuring... ANY ONE help?

Reply With Quote
  #10  
Old May 22nd, 2003, 09:23 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
/me thinks you need to call "popuate()" again before you go onto "addContent()"


Reply With Quote
  #11  
Old May 23rd, 2003, 03:26 AM
MstrDavid MstrDavid is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 MstrDavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Oh my!

That did it! Will teach me to rename my functions

Reply With Quote
  #12  
Old February 23rd, 2004, 06:31 PM
aid aid is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 aid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
WYSIWYG and populate data from DB

hi Nigor

having some truble with my code maybe u kan help (or someone else)

can populate data from DB in iframe (almoste).

the problem is that some DB data dont show in ifram (like bullit) but underline works ???

can someone help ???

//aid

Reply With Quote
  #13  
Old February 24th, 2004, 08:45 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
how does this relate to this thread?
perhaps you could achieve better results if you created a new thread for your question

Last edited by MadCowDzz : February 24th, 2004 at 08:48 PM. Reason: I see you did... ignore this post =)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > innerHTML question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |