JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with onclick Posted by tkline on 28 Jan 2004 at 8:24 AM
I have created a web page with a table that needs to add a row when the Add Row button is clicked. How do I capture the click event and do a loop to create another row in the table?

Thanks for the help!
Report
Re: help with onclick Posted by Weirdofreak on 28 Jan 2004 at 9:11 AM
<input type="button" onClick="addrow()">

function addrow() {
with (document)
var table = (getElementById)? getElementById('table') : all['table'];

table.addRow();
}


I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
Report
Re: help with onclick Posted by tkline on 29 Jan 2004 at 9:08 AM
:
<input type="button" onClick="addrow()">
: 
: function addrow() {
: with (document)
: var table = (getElementById)? getElementById('table') : all['table'];
: 
: table.addRow();
: }

:
: I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
:

I got this code to work but how do I add a check box not just text to the table?
td1.appendChild(document.createTextNode("want a check box here"))
Thanks!


function addRow(id){
    var tbody = document.getElementById
    (id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("column 1"))  //how do I get a check box or a text field?
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("column 2"))
    row.appendChild(td1);
    row.appendChild(td2);
tbody.appendChild(row);
  }

<a href="javascript:addRow('myTable')">Add row</a>

<table id="myTable" cellspacing="0" border="1">
  <tbody>
    <tr>
      <td>row1_column1</td><td>row1_column1</td>
    </tr>
  </tbody>
</table>


Report
Re: help with onclick Posted by Weirdofreak on 30 Jan 2004 at 12:24 AM
var check = document.createElement('input');
check.setAttribute('type','check');
td1.appendChild(check);

I think that's the one.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.