problem passing vars via anchor

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

problem passing vars via anchor

Post by garry27 »

i'm completely stumped with this one. i'd appreciate the help.

i've written a function which adds a row to a table. it works fine when i call it from google maps gevent double onclick event listener but when i try to call it in an onclick anchor, it messes up. it only lets me pass numerical vars no sring values.

here's the function i'm using:

Code: Select all

function addPubFn(pubID, pubName, pubPostcode)
{ 
  var tbody = document.getElementById('publist3').getElementsByTagName("tbody")[0];	  
	 
	  if (tbody.rows.length <10)
	  {         
        for (var i = 0; i < tbody.rows.length; i++) {
         if (tbody.getElementsByTagName("tr")[i].getElementsByTagName("td")[0]. 
		 firstChild.nodeValue == pubID) 
		 {	
          return; 
		 }
		} 
        var row = document.createElement("tr");
        var td1 = document.createElement("td");
        td1.appendChild(document.createTextNode(pubID));
        var td2 = document.createElement("td");
        td2.appendChild (document.createTextNode(pubName));
        var td3 = document.createElement("td");
        td3.appendChild (document.createTextNode(pubPostcode));
        row.appendChild(td1);
        row.appendChild(td2);
        row.appendChild(td3);
        tbody.appendChild(row);	
        //hide add pub link
		changeBodyClass("pp-div2-show","pp-div2-hide");
			
	  }
	  return false;			
} 

...the gevent listener...

Code: Select all

function createMarker(point, pubName, pubID, addPub, pubAddress, pubPostcode) 
{
  var marker = new GMarker(point);
  
...
...

  //add pub to crawl on marker dbl click  
  GEvent.addListener(marker,"dblclick", 
    function() {
	  addPubFn(pubID, pubName, pubPostcode);	  
    }
  );      return marker; 
}




and the anchor:

Code: Select all


function showPanel(pubID, pubName, pubAddress, pubPostcode, addPub)
...
...

	  
      //otherwise add content to panel and display   
      document.getElementById("pp-div2").innerHTML = "<a href='#' onClick='addPubFn(" + pubID + "," + pubName + "," + pubPostcode + "); return false;'>Add to Pub Crawl</a>";	  
      changeBodyClass("pp-div2-hide","pp-div2-show");

...
...
 
[/syntax]


this gives me the following eror in firebug: missing ) after argument list

you can see the scripts for yourself at: http://www.nl-webspace.co.uk/~unn_p9218 ... 556890128#

:wink:

Post Reply