Hello Everyone, I have a function here which ADDS a new row whenever the add button at the end of the row is pressed, can you help me change this function to one that would add a new textbox in the new row as well and change its name
Initially the name of the first textbox is SHName1
so when a new one is added I want it to be SHName2
and the next SHName3
and the next SHName4, etc...
Can you help me rewrite this function to do that rather than add a new row, I need it to add a new textbox inside the row...
In other words when Add is pressed I want to get a new textbox, instead of a new row... Also the add button should not be added more than once... the add button should be only one but when it is pressed it should add another textbox... Can this be done?
Here is my current code, but it's incorrect....
This is my code so far:
<form action="115-SHUpdate.asp" id="OPICForm" name="OPICForm" method="post" onSubmit = "return validateSubmit();" >
</div>
<%
'Get the saved values, if any
dim iApplicationID, sqlValues, rsValues
iApplicationID = Session("ApplicationID")
' Declare all of the values for Form 115
dim sSHName, sSHCountry, sSHPercentage
dim counter
counter = 0 '<--------THIS VARIABLE SHOULD KEEP TRACK OF HOW MANY ROWS HAVE BEEN ADDED BY THE USER
sqlValues = "SELECT * FROM Shareholders WHERE FK_ApplicationID=" & iApplicationID
set rsValues = Server.CreateObject("ADODB
.Recordset
")
with rsValues
.open sqlValues, objConn,3,3
if .Recordcount=1 then
' Save the values
sSHName = .Fields("SHName")
sSHCountry = .Fields("SHCountry")
sSHPercentage = .Fields("SHPercentage")
else
objConn.execute("INSERT INTO Shareholders (FK_ApplicationID) VALUES (" & iApplicationID & ")")
end if
end with
'.close
%>
<script language="javascript">
var bComplete = true;
function ValidateSubmit(){
bComplete = true;
alert(document.OPICForm.SH
Name);
//ValidateTextBox(document
.OPICForm.
SHName);
}
//START CODE THAT ADDS NEW ROWS WHEN THE ADD BUTTON IS PRESSED
function cloneRow(tblId)
{
var tbl = document.getElementById(tb
lId);
var tbody = tbl.getElementsByTagName('
tbody')[0]
;
var rowColl = tbody.getElementsByTagName
('tr');
var index = rowColl.length -1;
var row = rowColl[index];
var newRow = row.cloneNode(true);
setRow(newRow, index);
tbody.appendChild(newRow);
}
function setRow(row, index)
{
var inputs = row.getElementsByTagName('
input');
alert(inputs.value);
for(var i in inputs)
{
inputs[i].id = "whatever" + index + i;
inputs[i].name = "whatever" + index + i;
if(inputs[i].type == 'text')
{
inputs[i].value = "";
}
}
}
//END CODE THAT ADDS NEW ROWS WHEN THE ADD BUTTON IS PRESSED
</script>
</head>
<body>
<table id="mytable" class="content" width = "550" border = "1" cellpadding="1" cellspacing="1">
<thead>
<TR class = "heading">
<TD>
<strong>Shareholder Name</strong>
</TD>
<TD>
<strong>Country of Citizenship or Incorporation</strong>
</TD>
<TD>
<strong>Percent Owned</strong>
</TD>
<TD>
<strong>Add New Shareholder</strong>
</TD>
</TR>
</thead>
<tbody>
<TR>
<TD>
<input type = "text" name = "SHName" id = "SHName">
</TD>
<TD>
<input type = "text" name = "SHCountry" id = "SHCountry">
</TD>
<TD>
<input type = "text" name = "SHPercentage" id = "SHPercentage" size = "3" maxlength="3">
</TD>
<TD>
<input type = "button" name = "Add" value = "Add" onClick="cloneRow('mytable
');"/>
</TD>
</TR>
</tbody>
<tfoot>
<TR>
<TD colspan="3"> </TD>
</TR>
</tfoot>
</table>
<br><BR>
<center>
<input type="submit" id="submitShareholders" value="Submit Data" />
</center>
Start Free Trial