Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2007, 09:19 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Construct checkbox with Javascript

I have a web page with a table. I have a function that inserts a new row into that table:

function slow_insertRow(n)
{
    r = document.getElementById('theTable').insertRow(n)
    return r
}

and then I insert a series of cells into the row using, for example: c0 = r.insertCell(0)

In one of the cells, I want to create a checkbox. Now, I can simply write the HTML for a checkbox into the cell (by setting the innerHTML of the cell) - but that is no good because I cannot subsequently get a handle on the checkbox object (in fact, the object does not even exist).

So - how can I create a checkbox object in javascript, and insert it into my cell? When I have done that, I want to set its properties, such as id and value etc.

Hope you can help me achieve this. Thanks.

 
Old March 3rd, 2007, 04:17 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You should be able to create one using document.createElement("input") then set the type to checkbox and append it using cell.appendChild(). There was a problem in some older versions of IE that you couldn't set the name property effectively. If you need this then you'll have to test for IE and use document.createElement("<input type=\"checkbox\" name=\"chkWhatever\">") instead.

--

Joe (Microsoft MVP - XML)
 
Old March 3rd, 2007, 04:26 AM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I will try this. Is there a way I can destroy a previously-created element?

 
Old March 3rd, 2007, 04:34 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can use removeChild() or removeNode(). Look them up online.

--

Joe (Microsoft MVP - XML)
 
Old April 30th, 2012, 02:32 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Need to append two heads two textboxes to mytable using javascript

Hi friends,
Am padhu, am creating a application named job tracker in that there is a search page .i can a see employees status who are all working,not started and completed in that if any completes and not finished correctly then i have to reopen the same job for them.
so i need to append two heads and two textboxes,can any one helpme out from this prob.




Similar Threads
Thread Thread Starter Forum Replies Last Post
adding checkbox to datagrid using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 0 June 4th, 2007 11:02 PM
CheckBox enable in asp 2.0 with javascript bbsdev Javascript How-To 0 July 18th, 2006 12:27 PM
Use variables or other construct? jacob XSLT 4 November 15th, 2005 08:06 AM
php and javascript checkbox conflict sam PHP How-To 7 June 8th, 2004 06:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.