Web Hosting, Design, & Coding forum

General discussion

onClick with links

Hello all. I'm am pretty new to using javascript, xml, and xmlhttp request. I am trying to use xmlhttp with links. I have tried using onclick with the links and it doesn't work, I have also tried creating a function and putting that in with the link, but it doesn't work. If I create a button, the xmlhttp request works. Is it not possible to use xmlhttp with links, or am I just doing something wrong.

here is the script:
<script type="text/javascript">
var xmlhttp=null;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
document.getElementById('data').innerHTML=xmlhttp.responseText;
}
else
{
alert("Problem retrieving data:" + xmlhttp.statusText);
}
}
}
function click(url)
{
onclick="loadXMLDoc(url)"
}
</script>

and here are the links and button(I had to put periods behind the a's so it would show here):
<li><a. href="javascript:click('lwitherspoon.html')">Laurie E. Witherspoon</a></li>
<li><a. href="#" onclick="loadXMLdoc('php/inc/staff/lwitherspoon.html');return false">Quiana Ray</a></li>
<button onclick="loadXMLDoc('php/inc/staff/lwitherspoon.html')">Get XML</button>

Discussion is locked
You are posting a reply to: onClick with links
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: onClick with links
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.

Popular Forums

icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

SMART HOME

This one tip will help you sleep better tonight

A few seconds are all you need to get a better night's rest.