Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
dynamic div trouble

Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
New one
New one

Joined: 11 Sep 2008
Posts: 1

PostPosted: Thu Sep 11, 2008 5:29 pm    Post subject: dynamic div trouble Reply with quote

Here are the javascript functions I'm using:

// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;

// Change the value of the div
function setOutput(){
   if(httpObject.readyState == 4){
      document.getElementById('phone689235').innerHTML = httpObject.responseText;

// Implement the AJAX
function doWork(bid){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", "phonetrack.php?bid="+bid, true);
      httpObject.onreadystatechange = setOutput;

var httpObject = null;

And here's a sample of where and how it's being used:

<div id="phone689235"><a onclick="doWork('689235')">Show Phone Number</a></div>

I'm trying to implement a system by which a user clicks a link labeled 'Show Phone Number'. The contents of that div get replaced by the actual phone number by the backend PHP script phonetrack.php, which gets sent a parameter via AJAX. It looks up the phone number, records that 'hit' in a database and spits out the phone number

This works great 'as is'. But as you can see in the setOutput function, the div id hard coded. I need to make this dynamic. Here's what I've tried. This doesn't work:

changing the doWork function to have 2 parameters, like this:
doWork('689235', 'phone689235')

then changing the doWork function definition to
function doWork(bid, mydiv)
and changing the last line in the doWork function to
httpObject.onreadystatechange = setOutput(mydiv);

then changing the setOutput function to this:

function setOutput(mydiv){
   if(httpObject.readyState == 4){
      document.getElementById(mydiv).innerHTML = httpObject.responseText;

This DOES NOT WORK. Anybody know why not? Any help you could provide would be VERY appreciated!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 XML & Copyright Notice 

Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X

Link to our site:


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos

Normal Bookmark

Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax

Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?

it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert