47 3218
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.
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?
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. - var script = document.createElement("script");
-
script.src=theSrc; // string containing path to the JavaScript file
-
document.getElementsByTagName("head")[0].appendChild(script);
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.
gits 5,390
Expert Mod 4TB
... please post the code to have a look at ...
kind regards
... 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.
gits 5,390
Expert Mod 4TB
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
Merged your threads. Keep one problem to one thread.
See post #4.
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.
Create a script element and set the src property to the js file and then append to the head, e.g. - var script = document.createElement("script");
-
script.src=theSrc; // string containing path to the JavaScript file
-
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!
theSrc in this case would be "wysiwyg.js".
gits 5,390
Expert Mod 4TB
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: - var script = document.createElement("script");
-
script.src = 'function my_func() { alert("test"); }';
-
document.getElementsByTagName("head")[0].appendChild(script);
-
-
// call my_func - my_func is undefined
-
my_func();
-
but the following will work: - var script = document.createElement("script");
-
script.src = eval('function my_func() { alert("test"); }');
-
document.getElementsByTagName("head")[0].appendChild(script);
-
-
// now my_func is ready to use
-
my_func();
and even: - eval('function my_func() { alert("test"); }');
-
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
theSrc in this case would be "wysiwyg.js".
Hi I tried to put the code in this way: - // Main Page
-
-
<html>
-
<head>
-
<script type="text/javascript" src="Get_Page.js"></script>
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
<select id="attachMoreLink" name="select" onchange="getPage(this.value)">
-
<option selected="selected">--Select One--</option>
-
<option value="image">Image</option>
-
<option value="content">Text</option>
-
-
</select>
-
<div id="txtHint"> text will be displayed here</div>
-
</body>
-
</html>
-
//Page which to be called i.e. content.php -
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<script language="javascript">
-
var script = document.createElement("script");
-
script.src="wysiwyg.js"; // string containing path to the JavaScript file
-
document.getElementsByTagName("head")[0].appendChild(script);
-
</script>
-
<title>Untitled 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_Id" value="" /></td>
-
</tr>
-
<tr align="left">
-
<td valign="middle" align="left">Content Name </td>
-
<td valign="middle"><input type="text" name="Content_Name" value="" /></td>
-
</tr>
-
<tr align="left">
-
<td align="left" valign="top">Description</td>
-
<td valign="middle"><textarea id="textarea2" name="Content_Description" style="height: 200px; width: 500px;">
-
-
</textarea>
-
<script language="javascript1.2">
-
generate_wysiwyg('textarea2');
-
</script> </td>
-
</tr>
-
<tr align="left">
-
<td valign="middle"> </td>
-
<td valign="middle"><input type="submit" name="Content" value="Add Content" />
-
<input name="reset" type="reset" /></td>
-
</tr>
-
</table>
-
</body>
-
</html>
-
-
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 !
Hi I tried to put the code in this way: - // Main Page
-
-
<html>
-
<head>
-
<script type="text/javascript" src="Get_Page.js"></script>
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
<select id="attachMoreLink" name="select" onchange="getPage(this.value)">
-
<option selected="selected">--Select One--</option>
-
<option value="image">Image</option>
-
<option value="content">Text</option>
-
-
</select>
-
<div id="txtHint"> text will be displayed here</div>
-
</body>
-
</html>
-
//Page which to be called i.e. content.php -
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<script language="javascript">
-
var script = document.createElement("script");
-
script.src="wysiwyg.js"; // string containing path to the JavaScript file
-
document.getElementsByTagName("head")[0].appendChild(script);
-
</script>...
The JavaScript which adds the script to the page should be in the original page, not in the called page.
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. -
<script language="javascript1.2">
-
generate_wysiwyg('textarea2');
-
</script>
-
Thanks!
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: - var script2 = document.createElement("script");
-
var code = document.createTextNode("generate_wysiwyg('textarea2');");
-
script2.appendChild(code);
-
document.body.appendChild(script2);
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: - var script2 = document.createElement("script");
-
var code = document.createTextNode("generate_wysiwyg('textarea2');");
-
script2.appendChild(code);
-
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?
It should be on the main page after textarea2 has been added to the page.
It should be on the main page after textarea2 has been added to the page.
Hi
I tried to alert the code=documen.createText....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.
Hi
I tried to alert the code=documen.createText....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.
document.createTextNode() just creates a text node. appendChild adds it to the page. When the textarea has been added to the page via Ajax, then put this code after it. Note that this means that you will need to modify the PHP page. If you can't modify the page, you will need to parse the page to just get the HTML body for display and the JavaScript has to be added as I have described earlier.
document.createTextNode() just creates a text node. appendChild adds it to the page. When the textarea has been added to the page via Ajax, then put this code after it. Note that this means that you will need to modify the PHP page. If you can't modify the page, you will need to parse the page to just get the HTML body for display and the JavaScript has to be added as I have described earlier.
Hi
I am not able to do it. So if you may please help me out by modifying the code where it is necessary. I will be highle obliged to you. I know I must not say to you to write code but I think now I have messed up with the things. So please help me!
Thanks.
I am not able to do it. So if you may please help me out by modifying the code where it is necessary. I will be highle obliged to you. I know I must not say to you to write code but I think now I have messed up with the things. So please help me!
Show your latest version of the code.
The code which adds the scripts to the page should be added when content.html is called, otherwise it's not needed. If you're going to add them to the page before the option is selected, you might as well add them in the standard way, e.g.: - <script type="text/javascript" src="wysiwyg.js"></script>
The code which adds the scripts to the page should be added when content.html is called, otherwise it's not needed. If you're going to add them to the page before the option is selected, you might as well add them in the standard way, e.g.: - <script type="text/javascript" src="wysiwyg.js"></script>
Hi if you may do some modification to this code than it would be better for me just highlight the changes in the given code. Please!
Thanks
Here are some possible changes: - <html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<script type="text/javascript" src="Get_Page.js"></script>
-
<script type="text/javascript" src = "wysiwyg.js"></script>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
<form>
-
<select id="attachMoreLink" name="select" onchange="getPage(this.value)">
-
<option selected="selected">--Select One--</option>
-
<option value="image">Image</option>
-
<option value="content">Text</option>
-
-
</select>
-
<div id="txtHint"> text will be displayed here</div>
-
</form>
-
</body>
-
</html>
//Get_Page.js -
-
var xmlHttp;
-
var chosenOption;
-
function getPage(str)
-
{
-
chosenOption = str;
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
var image="image";
-
if(str==image)
-
{
-
var url="Get_Page.php";
-
url=url+"?q="+str;
-
url=url+"&sid="+Math.random();
-
xmlHttp.onreadystatechange=stateChanged ;
-
xmlHttp.open("GET",url,true);
-
xmlHttp.send(null);
-
}
-
else if(str=="content")
-
{
-
var url="content.html";
-
url=url+"?q="+str;
-
url=url+"&sid="+Math.random();
-
xmlHttp.onreadystatechange=stateChanged ;
-
xmlHttp.open("GET",url,true);
-
xmlHttp.send(null);
-
}
-
-
}
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
-
if (chosenOption == "content") generate_wysiwyg('textarea2');
-
}
-
}
-
//content.html -
<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_Id" value="" /></td>
-
</tr>
-
<tr align="left">
-
<td valign="middle" align="left">Content Name </td>
-
<td valign="middle"><input type="text" name="Content_Name" value="" /></td>
-
</tr>
-
<tr align="left">
-
<td align="left" valign="top">Description</td>
-
<td valign="middle"><textarea id="textarea2" name="Content_Description" style="height: 200px; width: 500px;">
-
-
</textarea>
-
</td>
-
</tr>
-
<tr align="left">
-
<td valign="middle"> </td>
-
<td valign="middle"><input type="submit" name="Content" value="Add Content" />
-
<input name="reset" type="reset" /></td>
-
</tr>
-
</table>
-
Woowwwwwwwww!!!!!!!! Grea88888888888888888.
Thanks. I am so happy now. Really you made me happy
Thanks a lot
Here are some possible changes:
Woowwwwwwwww!!!!!!!! Grea88888888888888888.
Thanks. I am so happy now. Really you made me happy
Thanks a lot
No problem! Glad it worked. If you have any more questions, just post again to the forum.
@acoder
Hi
I wanted to display like order details of particular client on the same page using ajax. Here is the process how it should work
browse name by alpha bate
a b c d e f g h i j
so when clicks say 'a' it will display all the name start with 'a' like this using ajax
amar
ajay
abhay
when user click any name say ajay it will display all the order made by him using ajax
order no qty
ty87a 10
mkd6a 5
mkd5a 7
when user will select order no say mkd5a it will display the details of this order underneath using ajax
and I wanted to do this using ajax so how can I do it. approach which I used is like calling a js page when user clicks any alpha bate and in that js page passing the url of the page which will display name.
In name displaying page again I called a function on its click event which calls js page and in that js page url is passed to display the order list and so on
but it is not working so how should I do it or my approach is wrong please advice me
A simple solution would be to have the JavaScript already within the parent page, so you can make multiple Ajax calls quite easily without having to load the JavaScript code too.
@acoder
Hi what I understood to call all js page in the parent page I did but it did not worked or I took it wrong.
What I meant is that the JavaScript code that you call, keep them in the parent page instead of using Ajax to load the code separately. You said:
approach which I used is like calling a js page when user clicks any alpha bate and in that js page passing the url of the page which will display name.
In name displaying page again I called a function on its click event which calls js page and in that js page url is passed to display the order list and so on
Instead of calling a JS page, have it already included on the parent page: - <script type="text/javascript" src="file.js">
@acoder
I did like this on the parent page -
<script type="text/javascript" src="file.js"> <!--to display name-->
-
<script type="text/javascript" src="fileabc.js"><!--to display order made by client xxx-->
-
<script type="text/javascript" src="filexyz.js"><!-- to display order details for a particular order number-->
-
but it is not working.
Of course, now you would have to call the functions defined within those files at the appropriate times/events.
@acoder
I am doing like this but it gives me error for fileabc.js that document.getElementById() is null which is not and most important when I call these files not a single ajax file is called because of this error mentioned above.
@mukeshrasm
there's probably something wrong with your html file. or the id value passed to this method. can't tell without the code or the page…
@Dormilich
here is the code file.html is the root file where i have called all the js files. -
<a href="#" onclick="clientName('I')">I</a>
-
<td id="c">name will be displayed here! </td>
-
<td id="p">projects will be displayed here! </td>
file.js -
var xmlHttp
-
function clientName(str)
-
{
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
var url="fileabc.html";
-
url=url+"?q="+str;
-
url=url+"&sid="+Math.random();
-
xmlHttp.onreadystatechange=stateChanged ;
-
xmlHttp.open("GET",url,true);
-
xmlHttp.send(null);
-
}
-
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
document.getElementById("c").innerHTML=xmlHttp.responseText;
-
-
}
-
}
-
-
function GetXmlHttpObject()
-
{
-
var xmlHttp=null;
-
try
-
{
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
try
-
{
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
here is the code for fileabc.html -
<a href="#" onclick="projectName('I')">mukesh</a><a href="#" onclick="projectName('A")">manish</a>
here is the code for fileabc.js -
var xmlHttp
-
function projectName(str)
-
{
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
var url="filexyz.html";
-
url=url+"?q="+str;
-
url=url+"&sid="+Math.random();
-
xmlHttp.onreadystatechange=stateChanged ;
-
xmlHttp.open("GET",url,true);
-
xmlHttp.send(null);
-
}
-
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
document.getElementById("p").innerHTML=xmlHttp.responseText;
-
-
}
-
}
-
-
function GetXmlHttpObject()
-
{
-
var xmlHttp=null;
-
try
-
{
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
try
-
{
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
here is code for filexyz.html -
<td >Information sytems</td><td >Inventory system</td>
-
I want that it should display the results underneath.
@mukeshrasm
unless you use Apache's mod_rewrite, there is no sense in passing parameters to a html file.
and a matter of personal preference, I'd pass the query string/parameters to the send() method. @mukeshrasm
underneath what? currently you're replacing the text in the table cells…
In addition to that, if it's a simple HTML file, you could just use JavaScript to add that content dynamically without the need for Ajax.
I can see where your problem is, though. You've defined GetXmlHttpObject twice. You only need it once. Secondly, you've already declared the global variable xmlhttp in file.js. Thirdly, you've redefined stateChanged(). Change that to something else in fileabc.js and change line 13 to reflect that.
@acoder
Thanks again! I fixed the errors now why I need to define GetXmlHttpObject once only and what problem stateChanged() caused in fileabc.js. and finally cann't I define global variables twice.
I am not calling html file actually it is dynamic file. that's why I am using ajax.
Thanks again!
Although it may not necessarily result in errors, it's bad practice to define the same function twice. In your case, stateChanged was different, so was the main cause of the problem. If you can, try to avoid global variables or keep to a minimum - see this.
@acoder
thanks! and useful link to learn if you have some more please refer me.
See the Off-site links sticky for some useful JavaScript links if you haven't already done so.
@acoder
Hi I want to give reference to some thread of this posting to php forum of this site how could I do this
You mean you want to refer/link to this thread? Just copy the URL in the address bar.
@acoder
ok thanks! actually I wanted to refer this thread to some of css and php topic of this site so for that I asked that how I will refer it to others.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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
-...
|
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"...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |