Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2011, 06:32 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default Button Updating Div

Hi,

I have a button on my page, and I want it to dynamically update the content of this <div> which has the id='mrs'.

I have tried and failed on several occasions. Any idea how to do it would be great. Please include code in the answer. I've tried various attempts of using the ajax html page requests and stuff.

Code:
function ajaxpage(div_id){
	var page_request = false
	if (window.XMLHttpRequest)
	{ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{ // if IE
		try 
		{
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e)
		{
		alert(e);
			try
			{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){
			alert(e);
			}
		}
	}
	else
	{
		return false
	}
	
	page_request.onreadystatechange=function(){
		addHtml(page_request, div_id);
	}
}

function addHtml(page_request, div_id)
{
if (page_request.readyState == 4 && page_request.status==200)
	var dr = document.getElementById(div_id).innerHTML;
	dr.innerHTML = "<a onclick='removeThis();'>Added Element</a>";
}
That's my failed attempt. Oh and if anyone can suggest how to do that "removeThis();" function which removes that given hyperlink that would be great!!

Cheers
__________________
Apocolypse2005, I'm a programmer - of sorts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Container <div> and another ,div. not behaving as expected SouthendSupporter ASP.NET 3.5 Basics 8 December 15th, 2009 10:05 AM
div within a div and inherting the height brettdavis4 CSS Cascading Style Sheets 1 January 23rd, 2007 09:59 AM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
how to use 'Enter' button to trigger a button, thx raybristol ASP.NET 1.0 and 1.1 Basics 1 December 16th, 2005 06:56 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.