Adding a function to a button

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default Adding a function to a button

    I'm trying to attach a javascript funtion to a button and I am having problems
    with it. Original the javascript function is attached to a dynamically created
    text string. Well when I want to attach the same function to the button it
    won't work, let me know what to do make this button work with the function.

    ~~~~~Script~~~~~

    function addRowClass(tableID, tableBody, instructionArray)
    {
    // write add link to page
    var oTable = document.getElementById(tableID);
    if(oTable)
    {
    // make the link
    oAddLink = document.createElement("a");
    oAddLink.setAttribute("href", "#");
    oAddLink.onclick = function() { addFormRow(tableBody, instructionArray);
    return false; }
    var oLinkText = document.createTextNode("Add Another Row");
    oAddLink.appendChild(oLinkText);

    document.body.insertBefore(oAddLink, document.body.firstChild);
    }
    }

    /* main function */ <--The Function I want to attach to button
    function addFormRow(tableBody, fieldArray)
    {
    tableBody = document.getElementById(tableBody);
    newRow = document.createElement("tr");
    rowNum = tableBody.getElementsByTagName("tr").length - 1; <-- ****The
    Error****

    for (var i = 0; i <= fieldArray.length; i++)
    {
    oCell = document.createElement("td");
    oInput = document.createElement("input");

    switch(fieldArray[0][i])
    {
    case "text":
    createTextbox(fieldArray[2][i], rowNum, fieldArray[1][i], fieldArray[3][i]);

    break;

    default:
    //an input error has occurred. Nothing will be written out to the cell.
    break;
    }
    oCell.appendChild(oInput)
    newRow.appendChild(oCell)
    }
    rowNum += 1;
    tableBody.appendChild(newRow)
    }

    ~~~~ERROR~~~~

    Line 149 * <-- ****The Error**** Located in the script
    "Null" is null

    ~~~~My Button~~~~
    <input type="button" name="Button1" value="Create Row" class="NewRowButton"
    value="javascript=addFormRow()">

    ~~~~End~~~~~

    Thanks for the help

    TGuthrie Guest

  2. Similar Questions and Discussions

    1. Adding paypal button
      I've just switched to Contriubte CS3 and can't figure out how to add the paypal button. Anybody know?????????
    2. Dynamically adding Dropdown, Text Box, Add Button and Remove Button
      Hi Everyone, I am facing a poblem in creating a row which contains following scenario in ASP.NET |DROP_DOWN_LIST | |TEXT_BOX| ...
    3. Adding a second button if the first button is clicked
      Hi I build my form dynamically in Page_Load, with a button If the user clicks the button I want to create another button. I can do this but the...
    4. adding lingo to a flash button
      hey guys. i need to be able to add some lingo to a flash button. the lingo needs to establish the global sound setting for multiple .dxr movies, and...
    5. Adding javascript function to update button in datagrid edit row
      I'd like to run a javascript function when you click the update button on an edit row, but I've no idea how I'd set it. Can't find any examples,...
  3. #2

    Default Re: Adding a function to a button

    The function has two arguments - tableBody and fieldArray - that need to get
    passed to it when it is called.

    Also, your button has two value attributes, which is going to cause problems.
    What you want is:
    <input type="button" name="Button1" value="Create Row" class="NewRowButton"
    onClick="javascript:addFormRow(some_reference_for_ tableBody,
    some_reference_for_fieldArray)">

    Rob Huddleston
    Adobe Dreamweaver Certified Developer

    robhuddles Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139