473,231 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Populate div with website using URL

Im new to the whole javascript game, I know pretty much just enough to be dangerous with no real substance. Anyway Im trying to populate a DIV with a website using the URL as an inner html source


Here is my code I keep getting an error object expecte don line 58. Which I will highlight. Anyway Not only would i Like to know what that error is about but also if my logic is correct or if I can even do what im trying... and if not what other solutions are there besides iframes.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script langauge="text/javascript">
  5.  
  6.  
  7. function reportsnagger(str)
  8. xmlHttp=GetXmlHttpObject();
  9. if (xmlHttp==null)
  10.   {
  11.   alert ("Your browser does not support AJAX!");
  12.   return;
  13.   } 
  14. var url="";
  15. url=url++str;
  16. xmlHttp.onreadystatechange=stateChanged;
  17. }
  18.  
  19. function stateChanged(showcustomer.url) 
  20. if (xmlHttp.readyState==4)
  21. document.getElementById(reportspace).innerhtml=url
  22.  
  23.  
  24. }
  25.  
  26. function GetXmlHttpObject()
  27. {
  28. var xmlHttp=null;
  29. try
  30.   {
  31.   // Firefox, Opera 8.0+, Safari
  32.   xmlHttp=new XMLHttpRequest();
  33.   }
  34. catch (e)
  35.   {
  36.   // Internet Explorer
  37.   try
  38.     {
  39.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  40.     }
  41.   catch (e)
  42.     {
  43.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  44.     }
  45.   }
  46. return xmlHttp;
  47. }
  48.  
  49. </script>
  50.  
  51. </head>
  52. <body>
  53. <form> 
  54. Select A Report:
  55. <select name="customers" onChange="reportsnagger(this.value)"> //this is line 58
  56. <option value="">Select an option please
  57. <option value="URL EDITED">choice1
  58. <option value="NORTS ">choice2
  59. <option value="WOLZA">choice3
  60. </select>
  61. </form><p>
  62. <div id="reportspace"><b>Report info will be listed here.</b></div>
  63. </p></body>
  64. </html>
Jul 17 '08 #1
6 4632
acoder
16,027 Expert Mod 8TB
First of all, welcome to Bytes!

There's a number of mistakes you've made. I would suggest you look at the source of a working example, or a simple Ajax tutorial to get you started. Check out the links in this thread.

Just a question though: is the URL from a different domain, i.e. not your site?

PS. changed the title to give the thread a better description.
Jul 17 '08 #2
aside from my mistakes if the site is on my web server i should be able to use as URL as innerhtml?

I have the basics down I believe, I understand there were some mistakes in my code could you be a dear and point them out? I know Im asking a lot especially for a new user but none of the references I've turned to have been much help asking specific question to a real life person would help me out tremendously.

If I can't use the object.innerhtml function then what should I use instead? I have the concept of what I want to do down, and have a basic understanding of how the script will be set up to handle it as you can see... I just don't have the practical part. All the tutorials I've read and the O'Reilly book I purchased cover some very usefull things but never specifically cover this issue as far as i can see.

While were on the subject will i need to call all the child and parent (nodes?) to make the site I pull in work correctly or will just simply referencing the URL allow it to function. Im sorry for being so needy but I really am at my wits end and none of the google grease i've been using has been helping.

BTW thanks for the welcome and Im glad your willing to help.
Jul 18 '08 #3
acoder
16,027 Expert Mod 8TB
If the website is from a different domain, i.e. not from your own site, you cannot access it unless you use some server-side code.

As for the mistakes, see these quick changes:
Expand|Select|Wrap|Line Numbers
  1. url = // a valid url
  2. url=url+str;
  3. xmlHttp.onreadystatechange=stateChanged;
  4. }
  5.  
  6. function stateChanged() 
  7.     if (xmlHttp.readyState==4)
  8.     { 
  9.         if(xmlHttp.status == 200) 
  10.         {
  11.             document.getElementById("reportspace").innerHTML=xmlHttp.responseText;
  12.         }
  13.  
  14.     }
  15. }
  16.  
Jul 19 '08 #4
The site I am trying to access is on my domain. I just wondered if I can use the document.innerhtml function or do i need another function to pull the page? Because it's technically html but i don't know if it will pull in the code or the precompiled page.

Also thanks for the code help, it's easy to over look those kind of errors in your own stuff.
Jul 22 '08 #5
i've rewritten my javascript but i need some help... the reference I used gave generic examples and Im not sure how to apply them to my specific situation like what variables to use... I hate coming here and essentially asking you to do this for me but I really am helpless...

heres the new code..

Expand|Select|Wrap|Line Numbers
  1. var request = false;
  2. var response;
  3. var currentObj;
  4.  
  5. function clearData(reportspace){
  6.     document.getElementById(reportspace).innerHTML = '';
  7. }
  8.  
  9. function loading(reportspace){
  10.     document.getElementById(reportspace).innerHTML = "Loading...";
  11. }
  12.  
  13. function ajaxRequest(url, data, reportspace){
  14.     currentObj = obj;
  15.     loading(currentObj);
  16.     if (window.XMLHttpRequest){
  17.         try{
  18.             request = new XMLHttpRequest();
  19.         }catch(e){
  20.             request = false;
  21.         }
  22.     }else if (window.activeXObject){
  23.         try{
  24.             request = new ActiveXObject("Msxml2.XMLHTTP");
  25.         }catch(e){
  26.             try{
  27.                 request = new ActiveXObject("Microsoft.XMLHTTP");
  28.             }catch(e){
  29.                 request = false;
  30.             }
  31.         }
  32.     }
  33.     request.onreadystatechange = handleData;
  34.     request.open("POST", url, true);
  35.     request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  36.     request.send(data);
  37.  
  38. }
  39.  
  40. function handleData(){
  41.     if (request.readyState == 4){
  42.         if (request.status == 200){
  43.             populateData(request);
  44.         }
  45.     }
  46. }
  47. function populateData(request){
  48.     data = request.responseText;
  49.     if (data != null){
  50.         clearData(currentObj);
  51.         document.getElementById(currentObj).innerHTML = data;
  52.     }else{
  53.         document.getElementById(currentObj).innerHTML = '';
  54.     }
  55. }
  56.  
the html page is the same except im now pulling the javascript in from a .js instead of imbedding it. Im still getting the object expected error on line 10 of the html any help would be appreciated
Jul 24 '08 #6
acoder
16,027 Expert Mod 8TB
You've not defined obj (line 14 in previous post) anywhere.
Jul 29 '08 #7

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

Similar topics

1
by: ziggs | last post by:
I have an asp form that has a text box called "colorBox". Just before text box is the word "Color" that is hyperlinked and will run the color.asp if pressed to show all of the colors in a...
5
by: Mark | last post by:
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder? Thanks! Mark
1
by: HalifaxPinball | last post by:
I want to collect data about some music in a database. Few tricky things that I have questions about... I'd like to start to populate the database with some info from a website. The web site is...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
7
by: Simon Gare | last post by:
Hi, have form on asp page that recalls data from the recordset and populates all the fields except the dynamic dropdown box that doesn't, just shows default value. How do I make it populate...
2
by: cdavenport4 | last post by:
Great Website! I have the following Code to populate a drop down with names but I'm have a problem with get the value to populate a POST Value. $ncaccntmg = $_POST; ~~~~~~~~~~~~~~~~~~~~~
6
by: peerraghu | last post by:
hi i am developing website which is a online shoping i want to populate two dropdownlist, in which the first dropdownlist should place the list of a paticular product and the next dropdownlist...
4
by: brad | last post by:
Hi there, New to javascript. Question about populating a form on a webpage that I do not control. I can see the field names and ids and currently have a button that onsubmit opens the page in a...
1
by: DavidPr | last post by:
I have a website that requires a visitor to register in order to make a post. I have one or two users that are violating the terms and every day I'm having to delete them. They just re-register,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.