Results 1 to 5 of 5

Thread: [RESOLVED] Javascript - how do I use the setAction command?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Resolved [RESOLVED] Javascript - how do I use the setAction command?

    I'm building a web page which lets the user add and remove rows of data entry fields to a table. As part of this I need to be able to add a delete button to each new row as it appears and set the onclick event for it to call the function I have which removes rows. I can't work out how to set the onclick event for a newly created item though. In the code below the second last line fails. What am I doing wrong?


    var tbl = document.getElementById("formTable");
    var row = tbl.insertRow(tbl.rows.length);
    cell = row.insertCell(1);
    cell.setAttribute("width","10%");
    var buttonVal = document.createElement("input");
    buttonVal.setAttribute("type", "image");
    buttonVal.setAttribute("id", "delbutton" + (numrows+1));
    buttonVal.setAttribute("name", "delbutton");
    buttonVal.src = 'skull_6.png';
    buttonVal.setAction("onclick", "removeFormItem(this);");
    cell.appendChild(buttonVal);

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Javascript - how do I use the setAction command?

    Try
    ButtonVal.onclick = function(){removeFormItem(this);};

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Javascript - how do I use the setAction command?

    What you are doing wrong is using a function without verifying with a reference that it exists - setAction doesn't.

    It's called attachEvent in IE and addEventListener in proper browsers.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Re: Javascript - how do I use the setAction command?

    Thanks for the help.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Javascript - how do I use the setAction command?

    Quote Originally Posted by CornedBee
    It's called attachEvent in IE and addEventListener in proper browsers.
    And with that in mind you can use this to make life easier.

Posting Permissions

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



Click Here to Expand Forum to Full Width