Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 12:17 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ]  Bookmark and Share
Author Message
 Post subject: Javascript:writetolayer
PostPosted: Fri Jan 09, 2009 10:21 pm 
Offline

Joined: Fri Jan 09, 2009 6:00 pm
Posts: 2
Hello, im newbie in php/html coding but I learn very fast :)

I have problem with one javascript.

There is the script:

Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Gregor (legreg@legreg.de) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
function hidelayer(lay) {
if (ie4) {document.all[lay].style.visibility = "hidden";}
if (ns4) {document.layers[lay].visibility = "hide";}
if (ns6) {document.getElementById([lay]).style.display = "none";}
}
function showlayer(lay) {
if (ie4) {document.all[lay].style.visibility = "visible";}
if (ns4) {document.layers[lay].visibility = "show";}
if (ns6) {document.getElementById([lay]).style.display = "block";}
}
function writetolayer(lay,php) {
if (ie4) {
document.all[lay].innerHTML = php;
}
if (ns4) {
document[lay].document.write(php);
document[lay].document.close();
}
if (ns6) {
over = document.getElementById([lay]);
range = document.createRange();
range.setStartBefore(over);
domfrag = range.createContextualFragment(php);
while (over.hasChildNodes()) {
over.removeChild(over.lastChild);
}
over.appendChild(domfrag);
   }
}
//  End -->
</script>


And there code to display layers

Code:
<SPAN ID="newlayer" style="position:absolute;">layer-text</SPAN>
<br><br><br>
<a href="javascript:hidelayer('newlayer');">hide layer</a> |
<a href="javascript:showlayer('newlayer');">show layer</a> |
<a href="javascript:writetolayer('newlayer','layer #1');">layer-text #1</a> |
<a href="javascript:writetolayer('newlayer','layer-text #2');">layer-text #2</a>
<br><br><br>


I want that "layer-text #1" will show info from my PHP file.

I tryed to get it with <? include "myfile.php" ?> but it dosent work :\

Can anyone help me ?


Top
 Profile  
 
 Post subject: Re: Javascript:writetolayer
PostPosted: Sat Jan 10, 2009 7:03 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
That can't be done with JS alone, you need AJAX to do that.

You might want to consider this script:
Code:
<script type="text/javascript">
/**
Title: Show/Hide Layer script
Author: Raymond Angana - [username = rangana in devppl.com/forum]
Created: 1/10/09
This notice must stay intact for legal use


Installation configuration:
hidelayer() - pass the id(s) of the layer you want to hide. Could work with multiple IDs

showlayer() - pass the id(s) of the layer you want to show. Could work with multiple IDs.

callFile() - first argument should be the URL of the file to call. The next argument is the ID of the layer you want the content of the file to show.

writetolayer() - first argument should be the text to write. The next argument(s) is the ID of the layer(s) you want the text be written. Could work with multiple IDs.
*/
var ray={
   hidelayer:function(){
      if(this.hidelayer.arguments.length>1){
         for(var i=0;i<this.hidelayer.arguments.length;i++)
            this.showHide(this.hidelayer.arguments[i],'none');
      }
      else this.showHide(this.hidelayer.arguments[0],'none');
   },
   
   showlayer:function(){
      if(this.showlayer.arguments.length>1){
         for(var i=0;i<this.showlayer.arguments.length;i++)
            this.showHide(this.showlayer.arguments[i],'');
      }
      else this.showHide(this.showlayer.arguments[0],'');
   },
   
   getID:function(el){
      return document.getElementById(el);
   },
   
   el:'',
   
   callFile:function(){
      this.el=this.el==''?this.callFile.arguments[1]:this.el;
      var xmlHttp;
      try{
         // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
      }
      catch (e){
         // Internet Explorer
         try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e){
            try{
               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
               alert("Your browser does not support AJAX!");
               return false;
            }
         }
      }
            
      xmlHttp.onreadystatechange=function(){
         if(xmlHttp.readyState==4){
            ray.showlayer(ray.el);
            ray.getID(ray.el).innerHTML=xmlHttp.responseText;
         }
      }
                  
      xmlHttp.open("POST",this.callFile.arguments[0],true);
      xmlHttp.send(null);
   },
   
   writetolayer:function(){
      if(this.writetolayer.arguments.length>2){
         for(var i=1;i<this.writetolayer.arguments.length;i++){
            this.showlayer(this.writetolayer.arguments[i]);
            this.getID(this.writetolayer.arguments[i]).innerHTML=this.writetolayer.arguments[0];
            }
      }
      else{
         this.showlayer(this.writetolayer.arguments[1]);
         this.getID(this.writetolayer.arguments[1]).innerHTML=this.writetolayer.arguments[0];
      }
   },
   
   showHide:function(el,disp){
      this.getID(el).style.display=disp;
   }
}
</script>
<span id="newlayer" style="position:absolute;">layer-text</span>
<br><br><br>
<a href="#" onclick="ray.hidelayer('newlayer');return false;">hide layer</a> |
<a href="#" onclick="ray.showlayer('newlayer');return false;">show layer</a> |
<a href="#" onclick="ray.callFile('myfile.php','newlayer');return false;">layer-text #1</a> |
<a href="#" onclick="ray.writetolayer('layer-text #2','newlayer');return false;">layer-text #2</a>


Your Javascript is so old, no need for document.all and those unnecessary detection for old browsers (IE5, Netscape).

The new script gives you the advantage to show/hide multiple layers at a time, by passing it as an argument to the available methods as explained below.

Methods available for ray object are as follows:

hidelayer() - pass the id(s) of the layer you want to hide. Could work with multiple IDs.

showlayer() - pass the id(s) of the layer you want to show. Could work with multiple IDs.

callFile() - first argument should be the URL of the file to call. The next argument is the ID of the layer you want the content of the file to show.

writetolayer() - first argument should be the text to write. The next argument(s) is the ID of the layer(s) you want the text be written. Could work with multiple IDs.

Hope that helps.

_________________
~ Get me some work, I do freelancing ~


Last edited by rangana on Sat Jan 10, 2009 3:08 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Javascript:writetolayer
PostPosted: Sat Jan 10, 2009 1:05 pm 
Offline

Joined: Fri Jan 09, 2009 6:00 pm
Posts: 2
Yes its working, thx for help man !


Top
 Profile  
 
 Post subject: Re: Javascript:writetolayer
PostPosted: Sat Jan 10, 2009 3:08 pm 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
No problem. Glad I could help.

You might want to use the recent script above. I've edited it to include comment on installation configuration.

Hope that helps.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley