473,662 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically create a tag with onclick

G'day guys,

i've looked around but i can't find how to create an A tag with a
onclick to remove a row in a table. Can add rows to table, but i can't
get it to create a link in the last coloumn to click to remove the row.

I've got:

var td6 = document.create Element("TD"); //create the TD
var link = document.create Element("a") //create element a
link.href = "test";
td6.appendChild (link); //add to the cell

the row function works fine but add a OnClick event to last coloumn i
can't seem to work out. Thanks guys.

Nov 4 '05 #1
1 2069
sh**********@gm ail.com wrote:
G'day guys,

i've looked around but i can't find how to create an A tag with a
onclick to remove a row in a table. Can add rows to table, but i can't
get it to create a link in the last coloumn to click to remove the row.

I've got:

var td6 = document.create Element("TD"); //create the TD
var link = document.create Element("a") //create element a
Don't use an A element for this, use a button or style a text element to
look 'clickable':

var textButton = document.create Element('span') ;
textButton.clas sName = 'clickable';
textButton.appe ndChild(documen t.createTextNod e('Delete row'));
textButton.oncl ick = deleteParentRow ;
td6.appendChild (textButton);

link.href = "test";
td6.appendChild (link); //add to the cell

the row function works fine but add a OnClick event to last coloumn i
can't seem to work out. Thanks guys.


The deleteParentRow function should look like:

function deleteParentRow ()
{
var el = this;
while(el.parent Node && 'tr' != el.nodeName.toL owerCase()){
el = el.parentNode
}
if ('tr' == el.nodeName.toL owerCase()) {
el.parentNode.r emoveChild(el);
}
}

The clickable style may be:

<style type="text/css">
.clickable {
cursor: pointer;
color: blue;
text-decoration: underline;
}
</style>
--
Rob
Nov 4 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8990
by: Terry | last post by:
I have a number of input boxes used to display totals based on selected items for each row in a table. There are more than a few rows that are identical, except for the form field name. I have added a sample of that below (there would be many more rows). I'm wondering if there is a way to dynamically generate the variable names (ie: T1val, T2val, etc.) in my function 'calc', based on the argument 'regnum' that I pass it. The problem...
8
9542
by: cool2005 | last post by:
I tried to dynamically add/clone a <tr> from an existing <tr> to a <table> but the problem is that I need to have a "onclick" event handler in the <tr>. I have tried following A. approach 1. 1. find the <tr> that I will insert <tr>s right after it
0
3157
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where there are tabs at the top with "submenu" buttons showing below the selected tab. The data that defines the tabs and submenus is stored in an XML file and I'm using nested repeaters to build them dynamically. I've got it working pretty well, except...
6
2372
by: bradb | last post by:
Hello, I have a textbox with an empty span element (place holder) next to it. When the user adds some text to the text box, I create a checkbox in the empty span element. When I create the checkbox I create a unique ID for the checkbox and associate an OnClick event with it. When I proceede to check that checkbox, I get a javascript error stating that the id is not defined. This is a dynamically created element, but shouldn't the ID of...
5
2864
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the elements in the form, including those that are added dynamically. I use document.getElementsByName('Field Name')to achieve the same.
9
2201
by: Donius | last post by:
Hey everyone, i am doing some stuff where i'd like to pop up a little confirmation before a user clicks on a 'delete' link. Just trying to keep the markup clean, i added an attribute pre_act="confirm" to all of the links that i wanted to do this to and am trying to add an onclick event that will cancel the click action if they fail. I've got a test page at http://randomwebspace.net/testing/testpage.html. It has no unintentional XHTML...
1
6502
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page. I am able to call values from file in my jsp page. But as dynamic values can be any in no...
2
3379
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and place it in the last cell of each row that I create dynamically using DOM methods. Everything is working well (that is, just like the original example) except for something related to the function behind my link. The link simply calls a function...
7
2524
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written several methods that are working fine. The problem is if I want to dynamically assign an event handler to the object, the event handler is not called. What am I doing wrong? Below is a sample HTML doc with everything in place. <!DOCTYPE HTML PUBLIC...
5
2297
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns like so: Dim column as TemplateColumn = new TemplateColumn() column.HeaderText = "Template Column" column.ItemStyle.Width = Unit.Pixel(width) column.HeaderStyle.Width = Unit.Pixel(width)
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.