Wrox Programmer Forums
|
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 July 8th, 2005, 04:51 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically Insert Row

Does anyone know how I can use the onChange event to dynamically add a row to a table that is a duplicate of the row I just changed?

  <tr>
    <td><cfselect name="prod1select" id="prod1select" onChange="javascript:addrow();">
        <option value="NULL" selected>Please select a product.</option>
      <cfoutput query="rsProducts">
        <option value="#ProductName#">#ProductName#</option>
      </cfoutput>
      </cfselect></td>
    <td><cfinput name="qty" type="text" id="qty" value="1" size="5" maxlength="2"></td>
  </tr>

I need to add a second row just like the above one after the onChange event...thoughts, anyone?



Clay Hess
__________________
Clay Hess
 
Old July 9th, 2005, 04:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well it would leave an invalid document because you'd have two elements with the same id, "prod1select". They'd also have the same name so you could have problems when reading submitted data.

That aside the code, in IE, would be something like:
Code:
onChange="addrow(this.parentElement.parentElement);

function addRow(Row)
{
  var oParent = Row.parentElement;
  var oNewRow = Row.cloneNode();
  oParent.appendChild(oNewRow);
}
Although you can change the id of the select after creation you can't change the name so you may want to build your own method of copying the select and then replacing the cloned one with that.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically add a new row to a existing GridView srkvellanki ASP.NET 2.0 Professional 1 September 21st, 2008 09:15 PM
apply css class to dynamically generated table row nikeshkm Javascript 2 September 28th, 2006 03:52 AM
Creating INSERT queries dynamically at runtime wpsprogrammer ADO.NET 3 January 26th, 2004 10:38 AM
dynamically change the row colors in datagrid bvrao VS.NET 2002/2003 0 December 24th, 2003 06:19 AM
Dynamically adding a row to a DataGrid vwindrow ASP.NET 1.x and 2.0 Application Design 2 August 20th, 2003 03:10 PM





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