473,795 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic table with dropdown and textboxes

18 New Member
Hi
I am using HTML and JS only.
When i click on Button(say Add) a new row will be added in to the table with dropdown's and textboxes.I want to know how to access the data entered in the textboxes and dropdowns
Please help me out as i am a beginner
Feb 18 '08 #1
20 3920
gits
5,390 Recognized Expert Moderator Expert
hi ...

please post the code you already have. basicly you may retrieve the values with:

Expand|Select|Wrap|Line Numbers
  1. // noderef is a reference to your node
  2. var val = noderef.value;
kind regards
Feb 18 '08 #2
daitasri
18 New Member
hi ...

please post the code you already have. basicly you may retrieve the values with:

Expand|Select|Wrap|Line Numbers
  1. // noderef is a reference to your node
  2. var val = noderef.value;
kind regards
Hi ,
This is the code i m using

Expand|Select|Wrap|Line Numbers
  1. function addRowToTable()
  2. {
  3.   var tbl = document.getElementById('t1head');
  4.   var lastRow = tbl.rows.length;
  5.   // if there's no header row in the table, then iteration = lastRow + 1
  6.   var iteration = lastRow;
  7.   var row = tbl.insertRow(lastRow);
  8.  
  9.   // left cell
  10.   var cell1 = row.insertCell(0);
  11.   var textNode = document.createElement('input');
  12.   textNode.setAttribute('type','text','name','text'+iteration,'id','txt'+iteration);
  13.   cell1.appendChild(textNode);
  14.  
  15.   // right cell
  16.   var cell2 = row.insertCell(1);
  17.   var el = document.createElement('input');
  18.   el.type = 'text';
  19.   el.name = 'text' + (iteration+1);
  20.   el.id = 'txt' + (iteration+1);
  21.   cell2.appendChild(el);
  22.  
  23.   // select cell
  24.   var cell3 = row.insertCell(2);
  25.   var sel3 = document.createElement('select');
  26.   sel3.name = 'request_access';
  27.   sel3.id='RA'+iteration;
  28.   sel3.options[0] = new Option('Y', '0');
  29.   sel3.options[1] = new Option('N', '1');
  30.   cell3.appendChild(sel3);
  31. }
  32.  
How can i save the values typed in textbox and dropdowns.
Thanks & Rgeards
daitasri
Feb 19 '08 #3
gits
5,390 Recognized Expert Moderator Expert
when do you want to save them? on a specific action like a button-click or submit? you just posted the code to append a line but that only creates the nodes ... later on the user types in something and then you may save the data. do you need to save it in a database? explain the requirement a bit more detailed please.

kind regards
Feb 19 '08 #4
daitasri
18 New Member
when do you want to save them? on a specific action like a button-click or submit? you just posted the code to append a line but that only creates the nodes ... later on the user types in something and then you may save the data. do you need to save it in a database? explain the requirement a bit more detailed please.

kind regards
Hi
The user types something in those textboxes and then clicks on "save" button then i need to save them into variables and also in database.I am using SQL Server as database.

Regards
Feb 19 '08 #5
gits
5,390 Recognized Expert Moderator Expert
you have some possibilities for that purpose:

1. submit the form and create a serverside save logic ... that would result in a page-reload ... which is the 'classical' way ...

2. use an XMLHttpRequest (AJAX-call) to send the request in the background and let the serverside code save the data to the database ... 'the modern up-to-date-way' ... that involves some clientside code in addition to the serverside one

kind regards
Feb 19 '08 #6
daitasri
18 New Member
Can u please send some examples of how to access the textboxes and data entered in textbox? I m not using AJAX. I need to do in javascript only. Please help me on this.
Feb 19 '08 #7
daitasri
18 New Member
I tried using textboxname.val ue also but it shows error. I named the textboxes as "text"+i where 'i' is getting incremented in a loop. I want to access the data entered in that textbox, using a javascript function and i want to store those values in some variables but not able to do.Request you to help on this.

Thanks
Feb 19 '08 #8
gits
5,390 Recognized Expert Moderator Expert
hi ...

assuming you have the following row:

[HTML]<table>
<tr>
<td><input type="text" value="test"/></td>
<td><input type="text" value="test1"/></td>
<td><input type="text" value="test2"/></td>
</tr>
</table>
[/HTML]
you may use something like the following simple function to retrieve the values of all the textboxes of that row:

Expand|Select|Wrap|Line Numbers
  1. function get_row_values(row) {
  2.     var record = {};
  3.     var fields = row.getElementsByTagName('input');
  4.  
  5.     for (var i = 0, node; node = fields[i]; i++) {
  6.         record['field' + i] = node.value;
  7.     }
  8.  
  9.     return record;
  10. }
  11.  
  12. var row = document.getElementsByTagName('tr')[0];
  13. var rec = get_row_values(row);
  14.  
  15. alert(rec.field0 + ' - ' + rec.field1 + ' - ' + rec.field2);
  16.  
that retrieves the values of all inputnodes found in a <tr>-element and stores it in an javascript object called 'record' ...

kind regards
Feb 19 '08 #9
daitasri
18 New Member
Hi
Thanks for your help.I tried that but it shows as 'undefined'. I m sending u the whole code which i am using.Please tell me wat is wrong in that or how can i modify to achieve my requirement.

[HTML]<html>
<head>
<script language="javas cript">
function createTable(id, ctr)
{
var tbody = document.getEle mentById(id).ge tElementsByTagN ame("TBODY")[0];
var i;
for(i=1;i<=ctr; i++)
{
var row1=document.c reateElement('T R');

var row1td1=documen t.createElement ('TD');
var row1td1_n=docum ent.createEleme nt('INPUT');
row1td1.appendC hild(row1td1_n) ;
row1td1_n.setAt tribute('TYPE', 'text');
// row1td1_n.setAt tribute('ID','u id'+i);
row1td1_n.setAt tribute('NAME', 'UID'+i);
row1td1_n.setAt tribute('ID','U ID'+i);



var row1td2=documen t.createElement ('TD');
var row1td2_n=docum ent.createEleme nt('INPUT');
row1td2.appendC hild(row1td2_n) ;
row1td2_n.setAt tribute('TYPE', 'text');
row1td2_n.setAt tribute('NAME', 'CID'+i);
row1td2_n.setAt tribute('ID','C ID'+i);


//row1td2.appendC hild(document.c reateElement('I NPUT' ));
//row1td2.setAttr ibute('TYPE','t ext','NAME','CN '+i);



var row1td3=documen t.createElement ('TD');
var row1td3sel=docu ment.createElem ent('select' );
row1td3sel.setA ttribute('id',' RA'+i,'NAME','r equest_access') ;
row1td3.appendC hild(row1td3sel );

var subrow3_y=docum ent.createEleme nt('option');
subrow3_y.inner HTML='Y';
subrow3_y.value =1;

var subrow3_n=docum ent.createEleme nt('option');
subrow3_n.inner HTML='N';
subrow3_n.value =2;
row1td3sel.appe ndChild(subrow3 _y);
row1td3sel.appe ndChild(subrow3 _n);


var row1td4=documen t.createElement ('TD');
var row1td4sel=docu ment.createElem ent('select' );
row1td4sel.setA ttribute('id',' PA'+i,'NAME','p reference_acces s');
row1td4.appendC hild(row1td4sel );

var subrow4_y=docum ent.createEleme nt('option');
subrow4_y.inner HTML='Y';
subrow4_y.value =1;

var subrow4_n=docum ent.createEleme nt('option');
subrow4_n.inner HTML='N';
subrow4_n.value =2;

row1td4sel.appe ndChild(subrow4 _y);
row1td4sel.appe ndChild(subrow4 _n);


var row1td5=documen t.createElement ('TD');
var row1td5sel=docu ment.createElem ent('select' );
row1td5sel.setA ttribute('id',' AA'+i,'NAME','a ctivity_access' );
row1td5.appendC hild(row1td5sel );

var subrow5_y=docum ent.createEleme nt('option');
subrow5_y.inner HTML='Y';
subrow5_y.value =1;

var subrow5_n=docum ent.createEleme nt('option');
subrow5_n.inner HTML='N';
subrow5_n.value =2;

row1td5sel.appe ndChild(subrow5 _y);
row1td5sel.appe ndChild(subrow5 _n);

var row1td6=documen t.createElement ('TD');
var row1td6sel=docu ment.createElem ent('select' );
row1td6sel.setA ttribute('id',' UR'+i,'NAME','u ser_rights');
row1td6.appendC hild(row1td6sel );

var subrow6_y=docum ent.createEleme nt('option');
subrow6_y.inner HTML='Y';
subrow6_y.value =1;

var subrow6_n=docum ent.createEleme nt('option');
subrow6_n.inner HTML='N';
subrow6_n.value =2;

row1td6sel.appe ndChild(subrow6 _y);
row1td6sel.appe ndChild(subrow6 _n);

var row1td7=documen t.createElement ('TD');
var row1td7btn=docu ment.createElem ent('input');
row1td7btn.setA ttribute('type' ,'button','name ','Del'+i);
row1td7btn.valu e='Delete';
row1td7btn.id=' Del'+i;
row1td7btn.oncl ick=function remove(){ removeRowFromTa ble(row1td7btn. id);};
row1td7.appendC hild(row1td7btn );



row1.appendChil d(row1td1);
row1.appendChil d(row1td2);
row1.appendChil d(row1td3);
row1.appendChil d(row1td4);
row1.appendChil d(row1td5);
row1.appendChil d(row1td6);
row1.appendChil d(row1td7);


tbody.appendChi ld(row1);
}

}

function addRowToTable()
{
var tbl = document.getEle mentById('t1hea d');
var lastRow = tbl.rows.length ;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(l astRow);

// left cell
var cell1 = row.insertCell( 0);
var textNode = document.create Element('input' );
textNode.setAtt ribute('type',' text','name','t ext'+iteration, 'id','txt'+iter ation);
cell1.appendChi ld(textNode);

// right cell
var cell2 = row.insertCell( 1);
var el = document.create Element('input' );
el.type = 'text';
el.name = 'text' + (iteration+1);
el.id = 'txt' + (iteration+1);
cell2.appendChi ld(el);

// select cell
var cell3 = row.insertCell( 2);
var sel3 = document.create Element('select ');
sel3.name = 'request_access ';
sel3.id='RA'+it eration;
sel3.options[0] = new Option('Y', '0');
sel3.options[1] = new Option('N', '1');
cell3.appendChi ld(sel3);

// select cell
var cell4 = row.insertCell( 3);
var sel4 = document.create Element('select ');
sel4.name = 'preferences_ac cess';
sel4.id='PA'+it eration;
sel4.options[0] = new Option('Y', '0');
sel4.options[1] = new Option('N', '1');
cell4.appendChi ld(sel4);

// select cell

var cell5 = row.insertCell( 4);
var sel5 = document.create Element('select ');
sel5.name = 'activity_acces s';
sel5.id='AA'+it eration;
sel5.options[0] = new Option('Y', '0');
sel5.options[1] = new Option('N', '1');
cell5.appendChi ld(sel5);

// select cell

var cell6 = row.insertCell( 5);
var sel6 = document.create Element('select ');
sel6.name = 'user_rights';
sel6.id='UR'+it eration;
sel6.options[0] = new Option('Y', '0');
sel6.options[1] = new Option('N', '1');
cell6.appendChi ld(sel6);

//button cell

var cell7 = row.insertCell( 6);
var el = document.create Element('input' );
el.type = 'button';
el.name = 'Del' + (iteration);
el.id = 'Del' + (iteration);
el.value='Delet e';
el.onclick=func tion remove(){ removeRowFromTa ble(el.id);};
cell7.appendChi ld(el);

}

</script>
<body bgcolor="#fffcd 0" onLoad=createTa ble('t1head',5) >
<form id=frm1 name=form1>
<table class="layout" border="4" align="center" width="100%" id=t1head>
<tr>
<td align="center"> <b> USER ID </b></td>
<td align="center"> <b> CLIENT </b></td>
<td align="center"> <b> REQUEST_ACCESS </b></td>
<td align="center"> <b> PREFERENCES_ACC ESS</b></td>
<td align="center"> <b> ACTIVITY_ACCESS </b></td>
<td align="center"> <b> USER_RIGHTS </b></td>

</tr>

</table>
<table>
<tr><td></td></tr><tr><td></td></tr>
<tr><td></td></tr></tr><tr><td></td></tr>
</tr><tr><td></td></tr><tr><td></td></tr>
<tr><td></td></tr></tr><tr><td></td></tr>
</table>
<table class="layout" border="0" align="center" id=tabBtn>
<tr>
<td align="center" colspan="2">
<input type="button" value="ADD" name="add" onClick=addRowT oTable()>
</td>

<td align="center" colspan="2">
<input type="button" value="SAVE" name="save" onClick=save1() >
</td>

<td align="center" colspan="2">
<input type="button" value="CANCEL" name="cancel" onClick="histor y.go(0)">
</td>
</tr>
</table>
</form>
</body>
</html>[/HTML]
Feb 19 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1103
by: Sachi | last post by:
Hi, I am looking for a optimized design for my problem. Purpose : Need to give a UI where user can select the layout they want. Initially we also need to give them one possible way to define rows and col. So I am providing two textbox to get this. After based on row and col i am generating a table. In which each TD will be showing dropdown to select which usercontrol to be load in different TD, which need to be stored in database.
1
4837
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that the table contains a SELECT box populated on the initial load. Every time I postback I'm inserting a column into the table, the dropdown always remains in the last column. First time I postback the dropdown is populated okay. The second time...
7
2366
by: Jeff Uchtman | last post by:
I know I have done this but my mind is fried. I have a dynamic dropdown in a form. I need to pull both the dynamic dropdown's ID and name listed in the dropdown. Need a little help with grey matter tonight. Thank Jeff
1
1274
by: Elliot Rodriguez | last post by:
I have a dropdown list that defines the number of textboxes that appear within a particular panel. The boxes are created when the dropdownlist's SelectedIndexChanged event fires on postback. Also in the form is a datagrid that has some custom validation performed on values within its rows. The validation is server side but not tied into any ValidatorControls. When the form is submitted, if the datagrid contains values that are invalid...
10
1925
by: B. Chernick | last post by:
I am using a System.Web.UI.WebControls.Table control on a screen. (Dot Net 1.1) My problem is this: The table is programmatically reconstructed on every postback. Each table row contains two textboxes that are intially set from the database. None of the items in the table are 'databound'. As of now, if the previous instance of the screen contained data in the first row boxes, that data is carried over, even if the boxes text value...
1
3414
by: theresa | last post by:
Hello. I'm creating a form that has (up to) 10 identical panels on the page, with each panel containing the same 8 textboxes for things like school name, address, etc, and one dropdown box. The user chooses how many schools they need to enter information for, and the form shows the appropriate number of panels. All 10 panels are generated on page load, then hidden until the user selects how many they need. Now comes the tricky part. If...
0
5293
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all the days in the week with dates and textboxes to fill in some data. row 1: question
0
1202
by: cruz | last post by:
Hi all, I am now developing an asp.net/C# web application. In this, in one aspx (say 'Parent page') page I am using two Iframes. Each Iframe source file (that are also .aspx file, say 'child1' and 'child2') contain a dropdown list control. According to the number selected in the dropdown, the page creates dynamic text boxes. For eg: if i select 5 from the dropdown list of child1, then child1 displays 5 dynamically generated textbox in...
2
5037
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final postback to enter the values in the dynamic textboxes into the database the values seem to become...
0
9522
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
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
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...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6784
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
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4114
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
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.