473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

dynamic add table row and pass value

Anyone know how to generate the number of textfield box equal to the value that I select from the dropdown list and click a button???
Jan 1 '08 #1
3 7804
Anyone know how to generate the number of textfield box equal to the value that I select from the dropdown list and click a button???
Hi there,

This is just a simple example of a script I made for you:
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>TextAreas</TITLE>
  4. <script type="text/javascript">
  5. function insertTextAreas(form) {
  6.     textAreas = document.forms['myform'].selects.value;
  7.     var container = document.getElementById("areas")
  8.     container.innerHTML = '';
  9.  
  10.     for(i=0; i<textAreas; i++)
  11.     {
  12.     var elem = document.createElement("textarea");
  13.     document.getElementById("areas").appendChild(elem);
  14.     }
  15.  
  16. }
  17.  
  18. </script>
  19. </HEAD>
  20. <BODY>
  21. <div id="areas">
  22.  
  23. </div>
  24.  
  25. <FORM NAME="myform" ACTION="" METHOD="GET">
  26. Enter something in the box: <BR>
  27. <select id="selects">
  28. <option>Please Select</option>
  29. <option value="10">10</option>
  30. <option value="15">15</option>
  31. <option value="20">20</option>
  32. </select>
  33. <input type="button" value="Submit" onclick="insertTextAreas(this.select)">
  34. </FORM>
  35. </BODY>
  36. </HTML>
  37.  
I believe this is what you need ?

P.S. Thanks to GITS for his notes :)
Best wishes!
Jan 2 '08 #2
gits
5,390 Expert Mod 4TB
hi ... to fix that simply put the following instead of line 10:

Expand|Select|Wrap|Line Numbers
  1. var container = document.getElementById("areas")
  2.  
  3. container.innerHTML = '';
  4. container.appendChild(elem);
one more note:

[HTML]<SCRIPT LANGUAGE="JavaScript"> [/HTML]
is deprecated ... use:

[HTML]<script type="text/javascript">[/HTML]
instead.

kind regards
Jan 2 '08 #3
Thanks Devil and gits...Anyway i had my own script...But I have 1 problem..
How do I get pass the values of the generated form to my database?

This is my codes:

<head>
<script type="text/javascript">
function addRowToTable() //call by the Add button
{
var tbl = document.getElementById('tblSample');

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(lastRow);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'member' + iteration;
el.id = 'member' + iteration;
el.size = 20; //text box size
el.onkeypress = keyPressTest; //call keyPressTest function
cellRight.appendChild(el);

// select cell
var cellRightSel = row.insertCell(2);
var sel = document.createElement('input');
sel.type = 'text';
sel.name = 'adminmember' + iteration;
sel.id = 'adminmember' + iteration;
sel.size = 20; //text box size
sel.onkeypress = keyPressTest2; //call keyPressTest function
cellRightSel.appendChild(sel);
}
function keyPressTest(e, obj) //call by the text box when onkeyPress, click Enter can auto add row
{ //e is event, obj is this text field object
var validateChkb = document.getElementById('chkValidateOnKeyPress'); //chkValidateOnKeyPress is a check box value to set want auto add row when enter is clicked or not
if (validateChkb.checked) {
var displayObj = document.getElementById('spanOutput');
var key;
if(window.event) {
key = window.event.keyCode;
}
else if(e.which) {
key = e.which;
}
var objId;
if (obj != null) {
objId = obj.id;
} else {
objId = this.id;
}
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
}
}
function keyPressTest2(e, obj) //call by the text box when onkeyPress, click Enter can auto add row
{ //e is event, obj is this text field object
var validateChkb = document.getElementById('chkValidateOnKeyPress'); //chkValidateOnKeyPress is a check box value to set want auto add row when enter is clicked or not
if (validateChkb.checked) {
var displayObj = document.getElementById('spanOutput');
var key;
if(window.event) {
key = window.event.keyCode;
}
else if(e.which) {
key = e.which;
}
var objId;
if (obj != null) {
objId = obj.id;
} else {
objId = this.id;
}
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
}
}
function removeRowFromTable() ///call by Remove button
{
var tbl = document.getElementById('tblSample'); //tblSample is table id
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function moveNumbers()
{
var no=document.getElementById("no");
var option=no.options[no.selectedIndex].text;
var txt=document.getElementById("result").value;
txt=txt + option;
document.getElementById("result").value=txt;
document.getElementById("clickit").disabled=true;
}
function resetit()
{
document.getElementById("no").disabled=false;
document.getElementById("clickit").disabled=false;
}
function validateFormOnSubmit(theForm) {
var reason = "";

reason += validatePassword(theForm.gppassword);
reason += validatePassword2(theForm.gppassword2,theForm.gppa ssword);
reason += validateEmail(theForm.maill);
reason += validateMember1(theForm.member1);
reason += validateMember1admin(theForm.adminmember1);
reason += validateMember2(theForm.member2);
reason += validateMember2admin(theForm.adminmember2);
reason += validateMember3(theForm.member3);
reason += validateMember3admin(theForm.adminmember3);


if (reason != "") {
alert("Some fields need correction:\n" + reason);
return false;
}

alert("All fields are filled correctly");
return false;
}
function validatePassword(fld) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter the password.\n";
} else if (fld.value.length < 7) {
error = "Please Enter at least 7 Characters for Password. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "The password contains illegal characters.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function validatePassword2(fld,fld2) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter the confirm password.\n";
} else if ((fld.value != fld2.value)) {
error = "Password Does Not Match.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function validateMember1(fld) {
var error = "";
var illegalChars = /[_]/; // allow only letters and numbers
var numbers = /[\d_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Please Enter Your Name for Member 1.\n";
} else if ((fld.value.length < 7) || (fld.value.length > 31)) {
error = "Please Enter Your Name Between 7-30 characters for Member 1. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Member 1 contains illegal characters or spacing.\n";
fld.style.background = 'Yellow';
} else if (numbers.test(fld.value)){
error = "Enter Only Alphabets for Member 1.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function validateMember1admin(fld) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers
var letters = /[\D_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "PLease Enter Your Admin Number for Member 1.\n";
} else if (!(fld.value.length == 7)) {
error = "Admin Number Length Error for Member 1. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Admin Number contains illegal characters or spacing for Member 1.\n";
fld.style.background = 'Yellow';
} else if (letters.test(fld.value)) {
error = "Please Enter Only Numbers for Member 1 Admin Number.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
} function validateMember2(fld) {
var error = "";
var illegalChars = /[_]/; // allow only letters and numbers
var numbers = /[\d_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Please Enter Your Name for Member 2.\n";
} else if ((fld.value.length < 7) || (fld.value.length > 31)) {
error = "Please Enter Your Name Between 7-30 characters for Member 2. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Member 2 contains illegal characters or spacing.\n";
fld.style.background = 'Yellow';
} else if (numbers.test(fld.value)){
error = "Enter Only Alphabets for Member 2.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function validateMember2admin(fld) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers
var letters = /[\D_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "PLease Enter Your Admin Number for Member 2.\n";
} else if (!(fld.value.length == 7)) {
error = "Admin Number Length Error for Member 2. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Admin Number contains illegal characters or spacing for Member 2.\n";
fld.style.background = 'Yellow';
} else if (letters.test(fld.value)) {
error = "Please Enter Only Numbers for Member 2 Admin Number.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
} function validateMember3(fld) {
var error = "";
var illegalChars = /[_]/; // allow only letters and numbers
var numbers = /[\d_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Please Enter Your Name for Member 3.\n";
} else if ((fld.value.length < 7) || (fld.value.length > 31)) {
error = "Please Enter Your Name Between 7-30 characters for Member 3. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Member 3 contains illegal characters or spacing.\n";
fld.style.background = 'Yellow';
} else if (numbers.test(fld.value)){
error = "Enter Only Alphabets for Member 3.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function validateMember3admin(fld) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers
var letters = /[\D_]/;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "PLease Enter Your Admin Number for Member 3.\n";
} else if (!(fld.value.length == 7)) {
error = "Admin Number Length Error for Member 3. \n";
fld.style.background = 'Yellow';
} else if (illegalChars.test(fld.value)) {
error = "Admin Number contains illegal characters or spacing for Member 3.\n";
fld.style.background = 'Yellow';
} else if (letters.test(fld.value)) {
error = "Please Enter Only Numbers for Member 3 Admin Number.\n";
fld.style.background = 'Yellow';
} else {
fld.style.background = 'White';
}
return error;
}
function trim(s)
{
return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
var error="";
var tfld = trim(fld.value); // value of field with whitespace trimmed off
var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter an email address.\n";
} else if (!emailFilter.test(tfld)) { //test email for illegal characters
fld.style.background = 'Yellow';
error = "Please enter a valid email address.\n";
} else if (fld.value.match(illegalChars)) {
fld.style.background = 'Yellow';
error = "The email address contains illegal characters.\n";
} else {
fld.style.background = 'White';
}
return error;
}
</script>
</head>

<%
call OpenDB()

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * from class", dbConn

Set rss = Server.CreateObject("ADODB.Recordset")
rss.Open "Select * from project", dbConn

set rsss = Server.CreateObject("ADODB.recordset")
rsss.Open "Select * From usergroup Order by gpid DESC ", dbConn
%>






<h2 class="title">
<span>Registration</span>
</h2><br>

<table border="0">
<form id="form1" name="form1" onsubmit="return validateFormOnSubmit(this)" method="post" action="groupregistration.asp">
<tr>
<td colspan=5><font size=3><u><b>Group Details</b></u></font></td>
<tr> <td width=19%>Project Class: </td>
<td width=22%><select name="class" id="no">


<% do while not rs.EOF

Response.write("<option value="""&rs("id")&""">"&rs("classes")&"</option>")
rs.MoveNext
loop
rs.Close
%>
</select>
<input type="button" onclick="moveNumbers()" value="Click it" id="clickit"> </td>
</tr>
<tr> <td>List of Projects: </td>

<td><select name="pjid">
<% do while not rss.EOF
Response.write("<option value="""&rss("id")&""">"&rss("pjname")&"</option>")
rss.MoveNext
loop
rss.Close
%>
</select></td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>Login name:</td>
<td><input type="text" name="gpusername" id="result" value="<%Response.Write("Gp"&(rsss("gpid")+1))%>" readonly="readonly"/></td>
<td>Auto Generated</td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="gppassword" maxlength="14"/></td>
<td>7~14 Characters</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="gppassword2" maxlength="14"/></td>

</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="maill" /></td>

</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=5><font size=3><u><b>Members Informations</b></u></font></td>
</tr>
<table border="1" id="tblSample">
<tr>
<th>No.</th>
<th>Members</th>
<th>Admin Numbers</th>
</tr>
<tr>
<td>1</td>
<td><input type="text" name="member1"
id="txtRow1" size="20" onKeyPress="keyPressTest(event, this);" /></td>
<td>
<input type="text" name="adminmember1"
id="adminmember1" size="20" onKeyPress="keyPressTest2(event, this);" /></td>

</tr>
</table>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="4"><div align="left">
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" />
<input type="button" value="Add Members" onClick="addRowToTable();" />
<input type="button" value="Remove Members" onClick="removeRowFromTable();" />
</div></td>
</tr>
<tr>
<td colspan=4><font size=1 color=red>*All fields are required.</font></td>
<tr><td colspan="4"><font size=1 color=red>Illegal characters are not allowed. eg.(%^&*!@#)</font></td>
</tr>
</form>
</table>

--------Groupregistration.ASP------------------------

<!--#include file="functions.asp"-->
<%
call OpenDB()

sql="INSERT INTO usergroup (gpname,gppass,projectid,priv,classid)VALUES ('"&Request.Form("gpusername")&"','"&Request.Form( "gppassword")&"','"&Request.Form("pjid")&"','1','" &Request.Form("class")&"')"
dbConn.Execute(sql)

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * from usergroup WHERE gpname='"&Request.Form("gpusername")&"'", dbConn
'Response.Write(rs("gpid"))
sql="INSERT INTO users (gpids,name,adminnum,class,priv)VALUES ('"&rs("gpid")&"','"&Request.Form("member1")&"','" &Request.Form("adminmember1")&"','"&Request.Form(" class")&"','1')"
dbConn.Execute(sql)
if not Request.Form("member2") = "" AND not Request.Form("member2admin") = "" then
sql="INSERT INTO users (gpids,name,adminnum,class,priv)VALUES ('"&rs("gpid")&"','"&Request.Form("member2")&"','" &Request.Form("adminmember2")&"','"&Request.Form(" class")&"','1')"
dbConn.Execute(sql)
end if
if not Request.Form("member3") = "" AND not Request.Form("member3admin") = "" then
sql="INSERT INTO users (gpids,name,adminnum,class,priv)VALUES ('"&rs("gpid")&"','"&Request.Form("member3")&"','" &Request.Form("adminmember3")&"','"&Request.Form(" class")&"','1')"
dbConn.Execute(sql)
end if


rs.close
Response.Redirect("index.asp")

%>

Would greatly appreciate help if some can enlighten me. I know for sure I need a Loop for my groupregistration.asp but I need some guides... Thanks a million!
Jan 2 '08 #4

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

Similar topics

0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
3
by: Susan | last post by:
I'm writing a stored procedure that uses DynamicSQL using the following code: SET @Get_Role_Number = 'Select @Role_Number = ' + @DatabaseName + '.dbo.sysusers.uid FROM ' + @DatabaseName +...
1
by: vsaraog | last post by:
Hi y'all I have a dynamic query in an application program written in C++ that I need to convert from Sybase to DB2. I am unable to figure out how to pass the variable in DB2. Following is the...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
5
by: drdave | last post by:
Hi, I have 6 forms being generated using coldFusion, they are named special1, special2 special3 and so on.. in these forms I have a link to open a new window. I am trying to pickup the...
5
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
1
by: philin007 | last post by:
Hi , I am having a page where leave is applied. - In this page 1 new rows is created dynamically everytime the 'Add row' button is pressed - Each row has a begin date text field and beside it a...
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
3
by: Andreas Wöckl | last post by:
Hi Group! I have a web form that is created dynamically - so I create Textboxes, RadioButtonLists, CheckBoxLists and so on - I have found some articles that there may be some problems with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.