homepage Welcome to WebmasterWorld Guest from 54.196.207.55
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Checking if the body html in an iframe is empty or notI
glimbeek




msg:4171491
 1:18 pm on Jul 16, 2010 (gmt 0)

I'm using Joomla and third party content manager which runs on taoj_contentmanager.1.0.4

In the contentmanager a user can create an article which must have a "Introtext" (this is checked by the JCE editor).
They can also fill in a Fulltext, in my case I want to user to always enter a fulltext so I want to create a check to make sure the fulltext isnt blank before saving.

I assumed this wouldn't be to difficult to do with a little bit of Javascript but as always, it seems more difficult then I expected.

In the FORM which handles it all the following Iframe is loaded:

<iframe frameborder="0" id="jxform[fulltext]_ifr" src="javascript:&quot;&quot;" style="width: 100%; height: 137px;"></iframe>

In the iFrame the following code is loaded

<html><head xmlns="http://www.w3.org/1999/xhtml"><meta content="IE=7" http-equiv="X-UA-Compatible"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<Loads of javascript files and code>
</head>
<body class="mceContentBody " id="tinymce" spellcheck="false" dir="ltr"><br _mce_bogus="1"></body>


I make sure my own javascript is loaded formcheck.js. As I said my goal is to check if the HTML in the body tag get's changed/isn't empty.

For now though creating an alert that displays the content of the body in the iframe is more then enough...

1 step at a time :)

I tried a lot of different approaches but I ended with this:

function checkForm() {
var form = document.getElementById["jxform[fulltext]_ifr"];
if(form == null) alert('form not found');
}


and this:

function checkForm() {
var form = document.adminForm;
if(form == null) alert('form not found');
var message = document.form["jxform[fulltext]_ifr"].body.innerHTML;
alert(message);
}


The above code doesn't work (obviously), so I'm hoping someone can help me out.

What's the right syntax to "call" the iFrame, it has the following id: jxform[fulltext]_ifr

What's the right syntax to "call/display" the content of a ID element that has square brackets in it's name?
I found the following solution: [jibbering.com...] but I can't get it to work.

With kind regards,

George

 

Fotiman




msg:4171526
 2:16 pm on Jul 16, 2010 (gmt 0)

document.form["jxform[fulltext]_ifr"] is the correct way to access the form named "jxform[fulltext]_ifr". But in your example, you have an iframe with an id of "jxform[fulltext]_ifr". Have you tried:

var iframe = document.getElementById("jxform[fulltext]_ifr");
var iframeBody = iframe.document.body;

I haven't tested that, but I think that's more along the lines of what you want to do. Hope that helps...

glimbeek




msg:4172667
 9:54 am on Jul 19, 2010 (gmt 0)

I had some help and this works:

function checkForm() {
var frame=document.getElementById("jxform[fulltext]_ifr");
var odoc=oframe.contentWindow.document;
if (odoc.body.innerHTML == '<br _mce_bogus="1">') {
var message="Fulltext cannot be empty!";
alert(message);
}
}

Cheers for the reply Fotiman!

glimbeek




msg:4173268
 12:13 pm on Jul 20, 2010 (gmt 0)

To make this work across a range of browsers:

function checkForm() {
var oframe = document.getElementById("jxform[fulltext]_ifr");
var odoc = oframe.contentWindow.document;
var strlenght = odoc.documentElement.getElementsByTagName('body')[0].innerHTML.length;
if (strlenght < 20) {
var message = "Fulltext cannot be empty!";
alert(message);
}
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved