Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.

Reply With Quote
  #2 (permalink)  
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)
Reply With Quote
  #3 (permalink)  
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?

Reply With Quote
  #4 (permalink)  
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)
Reply With Quote
  #5 (permalink)  
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.