|
-
Nov 20th, 2006, 10:45 PM
#1
Thread Starter
Addicted Member
[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);
-
Nov 21st, 2006, 04:28 AM
#2
Re: Javascript - how do I use the setAction command?
Try
ButtonVal.onclick = function(){removeFormItem(this);};
-
Nov 21st, 2006, 04:50 PM
#3
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.
-
Nov 22nd, 2006, 03:01 PM
#4
Thread Starter
Addicted Member
Re: Javascript - how do I use the setAction command?
-
Nov 23rd, 2006, 03:38 AM
#5
Re: [RESOLVED] Javascript - how do I use the setAction command?
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|