Jump to content

Code from W3Schools.com does not work! WHY?????


mgs019

Recommended Posts

Hi,

 

This is driving me slightly round teh twist.

 

I want to use an AJAX XMLhttprequest thingy to dynamically display diamond information in a webpage as the attributes change in hidden form elements controled by javascript sliders.

 

I am using an iframe at teh moment but it clicks like mad and is irritating so this seems far better.

 

However, I coied the code from the w3schools website and made a couple of very minor changes (the url) but it does not work!!!

 

The js file is associated because firefox web developer tools lists it correctly. The relevent HTML code is:

 

<div id="diadetails">Diamond details</div><input type="button" name="update" value="update" onmouseover="showUser()" />

 

Obviously the button is just to trigger it.

 

The script is:

 

var xmlHttpfunction showUser()
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="/includes/guideprice.php"
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("diadetails").innerHTML=xmlHttp.responseText 
} 
}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;
}

 

All that happens is that in internet explorer it says error on page at line ... char 1 object expected. It gives an error for every triggering. I just cannot figure out what object it wants.

 

Any idea guys this is really driving me insane ??? :'( >:(

 

Thanks alot.

 

Martin

Link to comment
Share on other sites

I was. But at the moment I am just trying to get anything to display. I had e.g.

 

var col = document.forms.colour.value

 

For several variables in the script which then add to the url. It works well in an iframe by changing the url using these variables.

 

However it did not work so I thought if I simplified it a bit it would be easier to work out where it is going wrong. Then I can add details later.

 

Martin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.