473,804 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem while calling two pages which includes Js pages

254 Contributor
Hi

I am calling two pages using Ajax Get_Pages.php and Get_Content.php from combo box. Both pages are displayed based on selection from combo box.

Main problem is that it is not showing the editor which is called on the Get_Content.php . in Main Page.

I have included the js files in the head section.

all the files are on the same directory.

But when I am running the Get_Content.php it is showing the Editors so what is the problem

Please help me out.

I have given the codes for the pages.
Main Page which is calling the JS Page.
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script src="Get_Page.js" type="text/javascript"></script>
  3. </head>
  4. <body>
  5. <form action="insertimage.php" method="post" enctype="multipart/form-data">
  6. <table><tr>
  7.  <td valign="middle">Page Type</td>
  8.             <td align="left" valign="bottom"><select name="Page_Type" onchange="getPage(this.value)">
  9.               <option>--Select One--</option>
  10.               <option value="image">Image</option>
  11.               <option value="content">Text</option>
  12. </td></tr>></table>
  13. </form>
  14. </body>

Expand|Select|Wrap|Line Numbers
  1. //js page
  2.  
  3. var xmlHttp
  4. function getPage(str)
  5.  
  6.     xmlHttp=GetXmlHttpObject()
  7.     if (xmlHttp==null)
  8.      {
  9.          alert ("Browser does not support HTTP Request");
  10.          return;
  11.      }
  12.      var image="image";
  13.     if(str==image)
  14.     {
  15.     var url="Get_Page.php";
  16.     url=url+"?q="+str;
  17.     url=url+"&sid="+Math.random();
  18.     xmlHttp.onreadystatechange=stateChanged ;
  19.     xmlHttp.open("GET",url,true);
  20.     xmlHttp.send(null);
  21.     }
  22.     else
  23.     {
  24.     var url="Get_Content.php";
  25.     url=url+"?q="+str;
  26.     url=url+"&sid="+Math.random();
  27.     xmlHttp.onreadystatechange=stateChanged ;
  28.     xmlHttp.open("GET",url,true);
  29.     xmlHttp.send(null);
  30.     }
  31.  
  32. }
  33. function stateChanged() 
  34.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  35.      { 
  36.          document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
  37.      } 
  38. }
  39. function GetXmlHttpObject()
  40. {
  41.     var xmlHttp=null;
  42.     try
  43.      {
  44.          xmlHttp=new XMLHttpRequest();
  45.      }
  46.     catch (e)
  47.      {
  48.          try
  49.           {
  50.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  51.           }
  52.          catch (e)
  53.           {
  54.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  55.           }
  56.       }
  57.     return xmlHttp;
  58. }
  59.  
Expand|Select|Wrap|Line Numbers
  1. //Get_Page.php
  2. <table>
  3. <tr valign="bottom">
  4.         <td width="20%" align="left" valign="middle">Caption1</td>
  5.         <td width="17%" align="left" valign="middle"><input name="Image_Name1" type="text" id="Image_Name" value="" size="15" /></td>
  6.         <td width="18%" align="center" valign="middle">File1: </td>
  7.         <td width="45%" align="left" valign="middle"><input name="File1" type="file" id="File1" value="" size="15" /></td>
  8.       </tr>
  9. <tr>
  10.         <td height="26" align="left" valign="middle">&nbsp;</td>
  11.         <td height="26" colspan="2" align="left" valign="bottom"><input type="submit" name="Upload" value="Upload"/>
  12.             <input type="reset" name="Reset" /></td>
  13.       </tr>
  14. </table>
  15.  
Expand|Select|Wrap|Line Numbers
  1. //Get_Content.php
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <script language="javascript" src="wysiwyg.js"></script>
  6. <title>Untitled Document</title>
  7. </head>
  8. <body>
  9.  
  10.     <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">
  11.       <tr align="left">
  12.         <td width="14%" align="left" valign="middle">&nbsp;&nbsp;&nbsp;&nbsp;Content Id </td>
  13.         <td width="86%" valign="middle"><input type="text" name="Content_Id" value="" /></td>
  14.       </tr>
  15.       <tr align="left">
  16.         <td align="center" valign="middle">Content Name </td>
  17.         <td valign="middle"><input type="text" name="Content_Name" value="" /></td>
  18.       </tr>
  19.       <tr align="left">
  20.         <td align="left" valign="top">&nbsp;&nbsp;Description</td>
  21.         <td valign="middle"><textarea id="textarea2" name="Content_Description" style="height: 200px; width: 500px;">
  22.  
  23.           </textarea>
  24.              <script language="javascript1.2">
  25.                   generate_wysiwyg('textarea2');
  26.             </script> </td>
  27.       </tr>
  28.       <tr align="left">
  29.         <td valign="middle">&nbsp;</td>
  30.         <td valign="middle"><input type="submit" name="Content" value="Add Content" />
  31.           <input name="reset" type="reset" /></td>
  32.       </tr>
  33. </table>
  34. </body>
  35. // end of page.
Now Problem is that code works fine but it is not showing the editor which is included through wysiwyg.js when I am calling it from main page.

But when I am running the Get_Content.php it shows the editor.

so is there any thing that I can not call Series of Js pages. If it is then how can I do it.
Dec 18 '07
47 3302
mukeshrasm
254 Contributor
Create a script element and set the src property to the js file and then append to the head, e.g.
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.src=theSrc; // string containing path to the JavaScript file
  3. document.getElementsByTagName("head")[0].appendChild(script);

Hi Acoder

I am not able to solve this problem. So If you can please tell me where I should put this code. Or If you may guide where should do the modification in this code to work this fine.

Thanks!
Jan 7 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
theSrc in this case would be "wysiwyg.js ".
Jan 7 '08 #12
gits
5,390 Recognized Expert Moderator Expert
as i said ... when the page is loaded and js is added later on ... this code has to be evaluated explicitly ...

for example - this will not work:

Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.src = 'function my_func() { alert("test"); }';
  3. document.getElementsByTagName("head")[0].appendChild(script);
  4.  
  5. // call my_func - my_func is undefined
  6. my_func();
  7.  
but the following will work:

Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.src = eval('function my_func() { alert("test"); }');
  3. document.getElementsByTagName("head")[0].appendChild(script);
  4.  
  5. // now my_func is ready to use
  6. my_func();
and even:

Expand|Select|Wrap|Line Numbers
  1. eval('function my_func() { alert("test"); }');
  2.  
would be enough :) so when getting scripts through ajax the code has to be evaled ... the same way as json has to be evaled ...

kind regards
Jan 7 '08 #13
mukeshrasm
254 Contributor
theSrc in this case would be "wysiwyg.js ".

Hi I tried to put the code in this way:
Expand|Select|Wrap|Line Numbers
  1.  //  Main Page
  2.  
  3. <html>
  4. <head>
  5. <script type="text/javascript" src="Get_Page.js"></script>
  6. <title>Untitled Document</title>
  7. </head>
  8.  
  9. <body>
  10. <select id="attachMoreLink" name="select" onchange="getPage(this.value)">
  11.               <option selected="selected">--Select One--</option>
  12.               <option value="image">Image</option>
  13.               <option value="content">Text</option>
  14.  
  15.             </select>
  16.             <div id="txtHint"> text will be displayed here</div>
  17. </body>
  18. </html>
  19.  
//Page which to be called i.e. content.php


Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <script language="javascript">
  6. var script = document.createElement("script");
  7. script.src="wysiwyg.js"; // string containing path to the JavaScript file
  8. document.getElementsByTagName("head")[0].appendChild(script);
  9. </script>
  10. <title>Untitled Document</title>
  11. </head>
  12.  
  13. <body>
  14. <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">
  15.       <tr align="left">
  16.         <td width="14%" align="left" valign="middle">Content Id </td>
  17.         <td width="86%" valign="middle"><input type="text" name="Content_Id" value="" /></td>
  18.       </tr>
  19.       <tr align="left">
  20.         <td valign="middle" align="left">Content Name </td>
  21.         <td valign="middle"><input type="text" name="Content_Name" value="" /></td>
  22.       </tr>
  23.       <tr align="left">
  24.         <td align="left" valign="top">Description</td>
  25.         <td valign="middle"><textarea id="textarea2" name="Content_Description" style="height: 200px; width: 500px;">
  26.  
  27.           </textarea>
  28.              <script language="javascript1.2">
  29.                   generate_wysiwyg('textarea2');
  30.             </script> </td>
  31.       </tr>
  32.       <tr align="left">
  33.         <td valign="middle">&nbsp;</td>
  34.         <td valign="middle"><input type="submit" name="Content" value="Add Content" />
  35.           <input name="reset" type="reset" /></td>
  36.       </tr>
  37. </table>
  38. </body>
  39. </html>
  40.  
  41.  
Note: Get_Page.Js page calls content.php in which the editor(wysiwyg. js) is used.

I think I must Hit my head to the Pole now !
Jan 7 '08 #14
acoder
16,027 Recognized Expert Moderator MVP
Hi I tried to put the code in this way:
Expand|Select|Wrap|Line Numbers
  1.  //  Main Page
  2.  
  3. <html>
  4. <head>
  5. <script type="text/javascript" src="Get_Page.js"></script>
  6. <title>Untitled Document</title>
  7. </head>
  8.  
  9. <body>
  10. <select id="attachMoreLink" name="select" onchange="getPage(this.value)">
  11.               <option selected="selected">--Select One--</option>
  12.               <option value="image">Image</option>
  13.               <option value="content">Text</option>
  14.  
  15.             </select>
  16.             <div id="txtHint"> text will be displayed here</div>
  17. </body>
  18. </html>
  19.  
//Page which to be called i.e. content.php


Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <script language="javascript">
  6. var script = document.createElement("script");
  7. script.src="wysiwyg.js"; // string containing path to the JavaScript file
  8. document.getElementsByTagName("head")[0].appendChild(script);
  9. </script>...
The JavaScript which adds the script to the page should be in the original page, not in the called page.
Jan 7 '08 #15
mukeshrasm
254 Contributor
The JavaScript which adds the script to the page should be in the original page, not in the called page.
Hi
Thanks for your kind guidance, one more thing I want to ask, what about the function which is in the wysiwyg.js page which actually do the things where I should put this code means in the content.html where textarea control is or in the main page where script object is created for wysiwyg.js page.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript1.2">
  2.  generate_wysiwyg('textarea2');
  3. </script>
  4.  
Thanks!
Jan 8 '08 #16
acoder
16,027 Recognized Expert Moderator MVP
Hi
Thanks for your kind guidance, one more thing I want to ask, what about the function which is in the wysiwyg.js page which actually do the things where I should put this code means in the content.html where textarea control is or in the main page where script object is created for wysiwyg.js page.
I see that you're calling the generate... function after the textarea with its ID. Does it matter where this function is called as long as it's after the textarea? If it doesn't matter, you can just append it to the body:
Expand|Select|Wrap|Line Numbers
  1. var script2 = document.createElement("script");
  2. var code = document.createTextNode("generate_wysiwyg('textarea2');");
  3. script2.appendChild(code);
  4. document.body.appendChild(script2);
Jan 8 '08 #17
mukeshrasm
254 Contributor
I see that you're calling the generate... function after the textarea with its ID. Does it matter where this function is called as long as it's after the textarea? If it doesn't matter, you can just append it to the body:
Expand|Select|Wrap|Line Numbers
  1. var script2 = document.createElement("script");
  2. var code = document.createTextNode("generate_wysiwyg('textarea2');");
  3. script2.appendChild(code);
  4. document.body.appendChild(script2);
Hi

I tried this code and put this code firstly on the caller page's body i.e. main page and then on the called page's body but still no result found. Don't know where I am wrong?
Jan 11 '08 #18
acoder
16,027 Recognized Expert Moderator MVP
It should be on the main page after textarea2 has been added to the page.
Jan 11 '08 #19
mukeshrasm
254 Contributor
It should be on the main page after textarea2 has been added to the page.
Hi

I tried to alert the code=documen.cr eateText....to get to know whether this function is getting the textarea2 but it is showing only object in alert message. So if textarea2 is not coming to the function how it will execute the editor.
Jan 11 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

31
3852
by: Bruce W...1 | last post by:
This is a best practices question. For a website where PHP is used, does it make sense to have both .htm and .php files? In other words, for pages that have no active content there's no point in naming them with a .php extension. Is there any advantage or disadvantage to making all files .php, or the same for mixing them with .htm files? What do you do, and why?
6
2727
by: Rob Long | last post by:
Hey, I've written a custom HTML library using many PHP scripts as seperate files (just like I'd do a java project) and I'm having some problems where I'm including scripts in different directories from already included scripts... basically where there'a an include chain spanning multiple directories. I've reduced the problem to its core:
3
1385
by: Keith | last post by:
I have a block of ASP code (enclosed in <% .. %>). How can I call that piece of code from another piece of similar code? And can the code be in any order on the page for it to work? Thanks
4
1572
by: Chad Richardson | last post by:
As I'm writing this I think I am answering my own question, but I'd like to get any other ideas on the subject as well. I have a standard Header.asp that I want to include in every other page in my site. Header.asp is located in the root folder, but the calling pages are in various folders/levels. Since the relative paths specified in header are subject to change and are based on the relative path of the calling page, problems arise....
2
4641
by: WisTex | last post by:
I've come across a very weird problem. Virtual includes work on all my ASP pages on the entire website, including those in subdirectories, yet they won't work on a particular page I created, even though the virtual include statement is copy & pasted exactly as it appears on the working pages. What would cause virtual includes to work in one page on a website, but not on another? Error Message: Microsoft VBScript runtime error...
78
4984
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my little helper function doesn't work! It claims that a variable doesn't exist. If I move the variable declaration, it finds the variable, but can't change it. Declaring the variable global in the nested function doesn't work...
8
1734
by: supasnail | last post by:
I have a happily working set of asp pages which read from the database via include file "./_private/include/database.mdb". However, when I try to gain access to this database on pages one folder removed using "../_private/include/database.mdb", the pages won't display. This whole system works fine on my home test server (iis.5.0), but 'breaks' when uploaded to the public server. I know the path to database is correct because the upper...
12
8466
by: Atlas | last post by:
I'm working on a multilanguage ASP/HTML site using a IIS6 web server. It perfectly works with two languages (english and italian) in this way: - basically the same ASP code for every language - language-specific content is stored in text files, every language has it's own directory contents. - to enhance usability and formatting the language-specific contents are stored with html syntax; basically the code that normally stands between...
17
1918
by: henry | last post by:
Folks Here's a skeleton, generic HTML page, call it "index.php". You'll see a bit of php code in the middle: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
0
9714
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
9594
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
10600
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
10096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5534
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
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.