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. - <html>
-
<head>
-
-
<script langauge="text/javascript">
-
-
-
function reportsnagger(str)
-
{
-
xmlHttp=GetXmlHttpObject();
-
if (xmlHttp==null)
-
{
-
alert ("Your browser does not support AJAX!");
-
return;
-
}
-
var url="";
-
url=url++str;
-
xmlHttp.onreadystatechange=stateChanged;
-
}
-
-
function stateChanged(showcustomer.url)
-
{
-
if (xmlHttp.readyState==4)
-
{
-
document.getElementById(reportspace).innerhtml=url
-
-
-
}
-
-
function GetXmlHttpObject()
-
{
-
var xmlHttp=null;
-
try
-
{
-
// Firefox, Opera 8.0+, Safari
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
// Internet Explorer
-
try
-
{
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
-
</script>
-
-
</head>
-
<body>
-
<form>
-
Select A Report:
- <select name="customers" onChange="reportsnagger(this.value)"> //this is line 58
-
<option value="">Select an option please
-
<option value="URL EDITED">choice1
-
<option value="NORTS ">choice2
-
<option value="WOLZA">choice3
-
</select>
-
</form><p>
-
<div id="reportspace"><b>Report info will be listed here.</b></div>
-
</p></body>
-
</html>
6 4644
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.
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.
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: - url = // a valid url
-
url=url+str;
-
xmlHttp.onreadystatechange=stateChanged;
-
}
-
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4)
-
{
-
if(xmlHttp.status == 200)
-
{
-
document.getElementById("reportspace").innerHTML=xmlHttp.responseText;
-
}
-
-
}
-
}
-
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.
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.. -
var request = false;
-
var response;
-
var currentObj;
-
-
function clearData(reportspace){
-
document.getElementById(reportspace).innerHTML = '';
-
}
-
-
function loading(reportspace){
-
document.getElementById(reportspace).innerHTML = "Loading...";
-
}
-
-
function ajaxRequest(url, data, reportspace){
-
currentObj = obj;
-
loading(currentObj);
-
if (window.XMLHttpRequest){
-
try{
-
request = new XMLHttpRequest();
-
}catch(e){
-
request = false;
-
}
-
}else if (window.activeXObject){
-
try{
-
request = new ActiveXObject("Msxml2.XMLHTTP");
-
}catch(e){
-
try{
-
request = new ActiveXObject("Microsoft.XMLHTTP");
-
}catch(e){
-
request = false;
-
}
-
}
-
}
-
request.onreadystatechange = handleData;
-
request.open("POST", url, true);
-
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
request.send(data);
-
-
}
-
-
function handleData(){
-
if (request.readyState == 4){
-
if (request.status == 200){
-
populateData(request);
-
}
-
}
-
}
-
function populateData(request){
-
data = request.responseText;
-
if (data != null){
-
clearData(currentObj);
-
document.getElementById(currentObj).innerHTML = data;
-
}else{
-
document.getElementById(currentObj).innerHTML = '';
-
}
-
}
-
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
You've not defined obj (line 14 in previous post) anywhere.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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;
~~~~~~~~~~~~~~~~~~~~~
|
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...
|
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...
|
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,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |