problem while calling two pages which includes Js pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    problem while calling two pages which includes Js pages

    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.
    Code:
    <head>
    <script src="Get_Page.js" type="text/javascript"></script>
    </head>
    <body>
    <form action="insertimage.php" method="post" enctype="multipart/form-data">
    <table><tr>
     <td valign="middle">Page Type</td>
                <td align="left" valign="bottom"><select name="Page_Type" onchange="getPage(this.value)">
                  <option>--Select One--</option>
                  <option value="image">Image</option>
    			  <option value="content">Text</option>
    </td></tr>></table>
    </form>
    </body>

    [CODE=javascript]//js page

    var xmlHttp
    function getPage(str)
    {

    xmlHttp=GetXmlH ttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var image="image";
    if(str==image)
    {
    var url="Get_Page.p hp";
    url=url+"?q="+s tr;
    url=url+"&sid=" +Math.random();
    xmlHttp.onready statechange=sta teChanged ;
    xmlHttp.open("G ET",url,true) ;
    xmlHttp.send(nu ll);
    }
    else
    {
    var url="Get_Conten t.php";
    url=url+"?q="+s tr;
    url=url+"&sid=" +Math.random();
    xmlHttp.onready statechange=sta teChanged ;
    xmlHttp.open("G ET",url,true) ;
    xmlHttp.send(nu ll);
    }

    }
    function stateChanged()
    {
    if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
    {
    document.getEle mentById("txtHi nt").innerHTML= xmlHttp.respons eText
    }
    }
    function GetXmlHttpObjec t()
    {
    var xmlHttp=null;
    try
    {
    xmlHttp=new XMLHttpRequest( );
    }
    catch (e)
    {
    try
    {
    xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
    }
    catch (e)
    {
    xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
    }
    }
    return xmlHttp;
    }
    [/CODE]

    [CODE=php]//Get_Page.php
    <table>
    <tr valign="bottom" >
    <td width="20%" align="left" valign="middle" >Caption1</td>
    <td width="17%" align="left" valign="middle" ><input name="Image_Nam e1" type="text" id="Image_Name " value="" size="15" /></td>
    <td width="18%" align="center" valign="middle" >File1: </td>
    <td width="45%" align="left" valign="middle" ><input name="File1" type="file" id="File1" value="" size="15" /></td>
    </tr>
    <tr>
    <td height="26" align="left" valign="middle" >&nbsp;</td>
    <td height="26" colspan="2" align="left" valign="bottom" ><input type="submit" name="Upload" value="Upload"/>
    <input type="reset" name="Reset" /></td>
    </tr>
    </table>
    [/CODE]

    [CODE=php]//Get_Content.php

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script language="javas cript" src="wysiwyg.js "></script>
    <title>Untitl ed Document</title>
    </head>
    <body>

    <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" >
    <tr align="left">
    <td width="14%" align="left" valign="middle" >&nbsp;&nbsp;&n bsp;&nbsp;Conte nt Id </td>
    <td width="86%" valign="middle" ><input type="text" name="Content_I d" value="" /></td>
    </tr>
    <tr align="left">
    <td align="center" valign="middle" >Content Name </td>
    <td valign="middle" ><input type="text" name="Content_N ame" value="" /></td>
    </tr>
    <tr align="left">
    <td align="left" valign="top">&n bsp;&nbsp;Descr iption</td>
    <td valign="middle" ><textarea id="textarea2" name="Content_D escription" style="height: 200px; width: 500px;">

    </textarea>
    <script language="javas cript1.2">
    generate_wysiwy g('textarea2');
    </script> </td>
    </tr>
    <tr align="left">
    <td valign="middle" >&nbsp;</td>
    <td valign="middle" ><input type="submit" name="Content" value="Add Content" />
    <input name="reset" type="reset" /></td>
    </tr>
    </table>
    </body>
    // end of page.[/CODE]
    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.
    Last edited by gits; Dec 18 '07, 04:26 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Originally posted by mukeshrasm
    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.
    You'll need to include the JavaScript file. Create a script object and add it to the head of the main page.

    Comment

    • mukeshrasm
      Contributor
      • Nov 2007
      • 254

      #3
      Originally posted by acoder
      You'll need to include the JavaScript file. Create a script object and add it to the head of the main page.
      But I have added the Get_Page.js to the head of main page. And how a script object will be created?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by mukeshrasm
        But I have added the Get_Page.js to the head of main page. And how a script object will be created?
        Create a script element and set the src property to the js file and then append to the head, e.g.
        [code=javascript]var script = document.create Element("script ");
        script.src=theS rc; // string containing path to the JavaScript file
        document.getEle mentsByTagName( "head")[0].appendChild(sc ript);[/code]

        Comment

        • mukeshrasm
          Contributor
          • Nov 2007
          • 254

          #5
          Problem in Ajax

          I have main form. In that form I have a dropdown box from that box I am calling two pages using ajax and page call is fired on onchange event of dropdown box.

          both pages are called if there is no javacript written on either page. But when I write some javascript code the javascript is not working on main form. so what can be problem.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            ... please post the code to have a look at ...

            kind regards

            Comment

            • mukeshrasm
              Contributor
              • Nov 2007
              • 254

              #7
              Originally posted by gits
              ... please post the code to have a look at ...

              kind regards
              Hi

              I tried to put some code here but it is showing some error. So what I mean to ask is that if a page has javascript function or calls to some js page so will the functionality of javascript/js page on this page be not reflected to the main page?
              If no then why it is not working here

              Say you have one main page which call a js page through ajax and in turn that page calls other js page so the functionality of this page will be work on main page or not.

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                nope ... in case you call a page through ajax the scripts in there are not evaluated except you do that explicitly ... so without having a look at the code or at least the response i only could guess the problem ...

                kind regards

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Merged your threads. Keep one problem to one thread.

                  See post #4.

                  Comment

                  • mukeshrasm
                    Contributor
                    • Nov 2007
                    • 254

                    #10
                    Originally posted by gits
                    nope ... in case you call a page through ajax the scripts in there are not evaluated except you do that explicitly ... so without having a look at the code or at least the response i only could guess the problem ...

                    kind regards

                    See the post #4 for your reference.

                    Comment

                    • mukeshrasm
                      Contributor
                      • Nov 2007
                      • 254

                      #11
                      Originally posted by acoder
                      Create a script element and set the src property to the js file and then append to the head, e.g.
                      [code=javascript]var script = document.create Element("script ");
                      script.src=theS rc; // string containing path to the JavaScript file
                      document.getEle mentsByTagName( "head")[0].appendChild(sc ript);[/code]

                      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!

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        theSrc in this case would be "wysiwyg.js ".

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5388

                          #13
                          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:

                          [CODE=javascript]var script = document.create Element("script ");
                          script.src = 'function my_func() { alert("test"); }';
                          document.getEle mentsByTagName( "head")[0].appendChild(sc ript);

                          // call my_func - my_func is undefined
                          my_func();
                          [/CODE]
                          but the following will work:

                          [CODE=javascript]var script = document.create Element("script ");
                          script.src = eval('function my_func() { alert("test"); }');
                          document.getEle mentsByTagName( "head")[0].appendChild(sc ript);

                          // now my_func is ready to use
                          my_func();[/CODE]

                          and even:

                          [CODE=javascript]eval('function my_func() { alert("test"); }');
                          [/CODE]
                          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

                          Comment

                          • mukeshrasm
                            Contributor
                            • Nov 2007
                            • 254

                            #14
                            Originally posted by acoder
                            theSrc in this case would be "wysiwyg.js ".

                            Hi I tried to put the code in this way:
                            [Code=html] // Main Page

                            <html>
                            <head>
                            <script type="text/javascript" src="Get_Page.j s"></script>
                            <title>Untitl ed Document</title>
                            </head>

                            <body>
                            <select id="attachMoreL ink" name="select" onchange="getPa ge(this.value)" >
                            <option selected="selec ted">--Select One--</option>
                            <option value="image">I mage</option>
                            <option value="content" >Text</option>

                            </select>
                            <div id="txtHint"> text will be displayed here</div>
                            </body>
                            </html>
                            [/Code]

                            //Page which to be called i.e. content.php


                            [Code=html]

                            <html>
                            <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                            <script language="javas cript">
                            var script = document.create Element("script ");
                            script.src="wys iwyg.js"; // string containing path to the JavaScript file
                            document.getEle mentsByTagName( "head")[0].appendChild(sc ript);
                            </script>
                            <title>Untitl ed Document</title>
                            </head>

                            <body>
                            <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" >
                            <tr align="left">
                            <td width="14%" align="left" valign="middle" >Content Id </td>
                            <td width="86%" valign="middle" ><input type="text" name="Content_I d" value="" /></td>
                            </tr>
                            <tr align="left">
                            <td valign="middle" align="left">Co ntent Name </td>
                            <td valign="middle" ><input type="text" name="Content_N ame" value="" /></td>
                            </tr>
                            <tr align="left">
                            <td align="left" valign="top">De scription</td>
                            <td valign="middle" ><textarea id="textarea2" name="Content_D escription" style="height: 200px; width: 500px;">

                            </textarea>
                            <script language="javas cript1.2">
                            generate_wysiwy g('textarea2');
                            </script> </td>
                            </tr>
                            <tr align="left">
                            <td valign="middle" >&nbsp;</td>
                            <td valign="middle" ><input type="submit" name="Content" value="Add Content" />
                            <input name="reset" type="reset" /></td>
                            </tr>
                            </table>
                            </body>
                            </html>

                            [/Code]

                            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 !
                            Last edited by gits; Jan 7 '08, 12:48 PM. Reason: fix code tags

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              Originally posted by mukeshrasm
                              Hi I tried to put the code in this way:
                              [Code=html] // Main Page

                              <html>
                              <head>
                              <script type="text/javascript" src="Get_Page.j s"></script>
                              <title>Untitl ed Document</title>
                              </head>

                              <body>
                              <select id="attachMoreL ink" name="select" onchange="getPa ge(this.value)" >
                              <option selected="selec ted">--Select One--</option>
                              <option value="image">I mage</option>
                              <option value="content" >Text</option>

                              </select>
                              <div id="txtHint"> text will be displayed here</div>
                              </body>
                              </html>
                              [/Code]

                              //Page which to be called i.e. content.php


                              [Code=html]

                              <html>
                              <head>
                              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                              <script language="javas cript">
                              var script = document.create Element("script ");
                              script.src="wys iwyg.js"; // string containing path to the JavaScript file
                              document.getEle mentsByTagName( "head")[0].appendChild(sc ript);
                              </script>...[/code]
                              The JavaScript which adds the script to the page should be in the original page, not in the called page.

                              Comment

                              Working...