473,890 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate div with website using URL

4 New Member
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 4689
acoder
16,027 Recognized Expert Moderator MVP
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
tinman486
4 New Member
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.innerhtm l 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 Recognized Expert Moderator MVP
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
tinman486
4 New Member
The site I am trying to access is on my domain. I just wondered if I can use the document.innerh tml 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
tinman486
4 New Member
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 Recognized Expert Moderator MVP
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
3808
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 predetermined 3 character code. Ex., BLU for Blue. Now, what I'd like to do is have the user enter all of the data in the main asp form, ex. Name, address, etc. When they come to the "colorBox", they will be allowed to enter "BLU" by hand or click on...
5
17149
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
2059
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 fed from another database that I do not have direct access to. I'd like to populate my lists such as genre, artist name, and song title. I'd also like to grab a thumbnail of the album cover, and in some cases an MP3 clip from the album. Can I...
3
2707
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 populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other words, a webpage may have to refer to 1 or more DataTables to populate itself. Therefore, a...
7
3989
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 based on the entry in the db? Regards Simon
2
2725
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
4849
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 should populate with the models of corresponding product of first dropdownlist1 and the price should be placed on the textbox please sought out my problem its urgent,my boss kept knife on my throat thanku in advance
4
3268
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 new window that contains the form I'd like to populate. Any tips on how to populate the form. We're trying to make it easier for users to submit it... no bots as it has a captcha.
1
2401
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, sometimes using a new email address (always a gmail account though). I want to create a database and enter banned email addresses. Then I want to populate an array using these banned email addresses. When someone tries to register I want to check to...
0
9812
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
11212
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
10799
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10446
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
9614
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
5832
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...
2
4255
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3263
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.