DOM/DHTML to pass vars 2x one function builds another call  using JAVASCRIPT

Posted on 2007-10-12
Last Modified: 2013-11-19
Hello  I have a startEditing function that has to "build" a href call to another function and pass 2 vars (a,b)
Those a,b are fine this startEditing function ( I can print them out to see them there), but I get an "a is undefined" when I click the new built href calling saverecord function I just built. what am I doing wrong?
BTW this all works perfectly except for when I add this passing of these vars - I need them for the save.

function startEditing(trObj,a,b) {
      var arrColumnNames = getColumnNames(trObj.parentNode.parentNode);
      var tdObjs = trObj.getElementsByTagName('TD');
      tdObjs[0].innerHTML = '<a class="save" href="#" onclick="saveRecord(this,a,b);" title="Save this record"><span>Save</span></a>';
      tdObjs[1].innerHTML = '<a class="cancel" href="#" onclick="cancelEditRecord(this);" title="Cancel editing"><span>Cancel</span></a>';
      for (var i=2;i<tdObjs.length;i++)
            tdObjs[i].innerHTML = '<input type="text" name="'+arrColumnNames[i-2]+'" id="input-'+arrColumnNames[i-2]+'" value="'+tdObjs[i].innerHTML+'" default="'+tdObjs[i].innerHTML+'">';
            tdObjs[i].innerHTML = '<input type="hidden" name="'+arrColumnNames[i-2]+'"     id="input-'+arrColumnNames[i-2]+'" value="'+tdObjs[i].innerHTML+'" default="'+tdObjs[i].innerHTML+'">';
      return false;

function saveRecord(obj,a,b) {

      //           A      TD         TR    
      var trObj = obj.parentNode.parentNode;
      //              TR     TBODY      TABLE
      var tableObj = trObj.parentNode.parentNode;
      var inputObjs = trObj.getElementsByTagName('INPUT');
      var rowId =;
      var url =;
      // Call SET/ADD method to save record to the database
      if ((rowId) && (rowId != ""))
            url += '.cfc?method=set&rowId=' + rowId;
            url += '.cfc?method=add';
      for (var i=0;i<inputObjs.length;i++)
            url += '&' + inputObjs[i].name + '=' + inputObjs[i].value;
        // set the owner and level vars passed in
        url += '&ownerid=' + b;
        url += '&levelid=' + a;
      var response = wddxGetElement(httpRequest(url),'string');
      if (response.substr(0,2) != "id") alert(response);
      else {
   = response.substr(3);

Question by:madpuppy
    LVL 23

    Accepted Solution

    may i ask, what type of object is stored in the variables a and b?

    the problem is here: onclick="saveRecord(this,a,b);"
    you are just saying that onclick is this string: "saveRecord(this,a,b);"  'a' and 'b' are just part of the string, they have nothing to do with the variables you passed into the function...

    i'd have to do some experiments, but you could start by trying this:

    onclick="saveRecord(this,' + a + ',' + b' + ');"

    Author Comment

    Thank you that was it I thought I could get off easy on all those wee '

    Thanks tons

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now