Hi!
I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks the delete button selected row wants to delete.
My problem is(If i delete the first row, its say undefined and change the value is 0) pls check my program. -
<%pathdefiner = "../"%>
-
<!--#include file="../connection/connector.asp" -->
-
<!--#include file="declareVariables.asp" -->
-
<!--#include file="../MainMenu/Header.htm" -->
-
-
-
-
-
<script language="JavaScript" type="text/javascript">
-
<!--
-
var hasLoaded = false;
-
-
function addRowToTable()
-
{
-
var c=0;
-
// var nos=1;
-
// var i;
-
-
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;
-
//document.write ("iteration = " + iteration);
-
-
if(lastRow == 7)
-
{
-
alert("Only six countrys");
-
}
-
else{
-
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 = 'txt_C' + iteration;
-
el.id = 'txt_C' + iteration;
-
el.size = 40;
-
-
el.onkeypress = keyPressTest;
-
cellRight.appendChild(el);
-
-
-
// text box cell
-
var textRight = row.insertCell(2);
-
var el = document.createElement('input');
-
el.type = 'text';
-
el.name = 'txt_F' + iteration;
-
el.id = 'txt_F' + iteration;
-
el.onfocus = function(event){return showCalendarControl(this);};
-
el.size = 20;
-
el.onblur = this;
-
el.readOnly = this;
-
-
el.onkeypress = keyPressTest;
-
textRight.appendChild(el);
-
-
// text box cell
-
var txtRight = row.insertCell(3);
-
var el = document.createElement('input');
-
el.type = 'text';
-
el.name = 'txt_T' + iteration;
-
el.id = 'txt_T' + iteration;
-
el.onfocus = function(event){return showCalendarControl(this);};
-
el.size = 20;
-
el.onblur = this;
-
el.readOnly = this;
-
-
el.onkeypress = keyPressTest;
-
txtRight.appendChild(el);
-
-
// Delete Button
-
var btnRight = row.insertCell(4);
-
var el = document.createElement('input');
-
el.type = 'button';
-
el.name = 'btnDel' + iteration;
-
el.id = 'btnDel' + iteration;
-
el.value = 'Delete'
-
el.onfocus = function(event){return removeRowFromTable(this);};
-
el.onkeypress = keyPressTest;
-
btnRight.appendChild(el);
-
-
-
-
//Row count
-
lastRow = c+lastRow
-
document.frm.txt_count.value = lastRow;
-
-
}
-
}
-
-
function keyPressTest(e, obj)
-
{
-
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;
-
}
-
}
-
-
-
function removeRowFromTable(r)
-
{
-
var i=r.parentNode.parentNode.rowIndex;
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
alert(i);
-
if (lastRow > 2 )
-
{
-
alert("i"+i);
-
tbl.deleteRow(i+1);
-
}
-
else
-
{
-
alert("Please enter 'NIL' for country if your are not travelling");
-
return;
-
}
-
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
//frm.action = "Remove_Data.asp";
-
//frm.submit();
-
}
-
-
function onloa()
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
}
-
-
function validateRow(frm)
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
var i;
-
var compDate,j;
-
-
for (i=1; i<=lastRow; i++) {
-
var aRow = document.getElementById('txt_C' + i);
-
var FDate = document.getElementById('txt_F' + i).value;
-
var TDate = document.getElementById('txt_T' + i).value;
-
var country = document.getElementById('txt_C' + i).value;
-
-
country = country.toUpperCase();
-
-
-
if (aRow.value.length <= 0) {
-
alert('The country ' + i + ' is empty');
-
return;
-
}
-
var test;
-
test = "NIL"
-
compDate = TDate - FDate;
-
-
if (FDate>TDate) {
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
-
// else
-
if (country != test)
-
{
-
if(FDate == "NaN" || TDate == "NaN")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
-
else if(FDate == "" || TDate == "")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
}
-
-
-
// else
-
// {
-
// alert("Please enter the Date" + i);
-
// return;
-
// }
-
-
}// for loop end
-
-
if(document.getElementById('tet_Name_PG').value == "NIL" || document.getElementById('tet_Name_PG').value == "")
-
{
-
alert("Please enter Name of Parent/Guardian. ");
-
return;
-
}
-
-
var cons;
-
cons = document.getElementById('tet_Contact').value;
-
-
if (!Number(cons))
-
{
-
alert('Please enter Parent/Guardian Contact no.')
-
// frm.tet_Contact.focus();
-
return;
-
}
-
-
-
frm.submit();
-
}
-
-
function Stud_Qual()
-
{
-
if(document.getElementById("txt_C1").value == "NIL")
-
{
-
document.getElementById("txt_F1").value = document.getElementById("txt_C1").value;
-
document.getElementById("txt_T1").value = document.getElementById("txt_C1").value;
-
}
-
-
}
-
function MM_jumpMenu(targ,selObj,restore){ //v3.0
-
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
-
if (restore) selObj.selectedIndex=0;
-
}
-
//-->
-
</script>
-
<style type="text/css">
-
<!--
-
.style3 {
-
font-size: 1px;
-
color: #FFFFFF;
-
}
-
.style4 {
-
font-size: 24px;
-
font-weight: bold;
-
color: #003333;
-
}
-
.style9 {font-size: 18px; font-weight: bold; }
-
.style10 {color: #EE0000}
-
-->
-
</style>
-
-
<%
-
Dim retrieveSql, rSql
-
retrieveSql = "SELECT * FROM "& TBL_LOGIN & " WHERE " & TFL_IC & "='"& Session.Contents("IDNO") &"';"
-
-
Set rsRetrieve = Server.CreateObject("ADODB.Recordset")
-
Set rsRetrieve.ActiveConnection = my_Conn
-
-
rsRetrieve.Source = retrieveSql
-
rsRetrieve.Open
-
-
-
if rsRetrieve.EOF Then
-
else
-
do until rsRetrieve.EOF
-
%>
-
<form name="frm" id="frm" method="post" action="Update_Data.asp">
-
<table align="center" width="300" border="2" cellspacing="0" cellpadding="0" bordercolor="#004400" bgcolor="#e5ffe5">
-
<tr>
-
<td><img src="../images/overseas_travel5.jpg" width="872" height="242"></td>
-
</tr>
-
<tr>
-
<td>
-
<p> </p>
-
<p align="center" class="style4">INFORMING SCHOOL OF CHILD'S/WARD'S TRAVEL PLANS</p>
-
<p> </p>
-
-
<div align="center">
-
<p> </p>
-
<select name="travel" id="travel" onChange="javascript:YesOnclick('travel', 'SPAN_travel', 'YES')">
-
<option value="NIL">--Choose one--</option>
-
<option value="YES"> Travelling </option>
-
<option value="NO"> Not_Travelling </option>
-
</select>
-
-
<p> </p>
-
</label></div>
-
-
<table width="595" align="center" border="0" cellspacing="3" cellpadding="2">
-
<tr>
-
<td width="189"><span class="style9">Name of Child/Ward</span></td>
-
<td width="16"><div align="center">:</div></td>
-
<td width="334"> <b><% =rsRetrieve("Name")%></b></td>
-
</tr>
-
<tr>
-
<td><span class="style9">NRIC/FIN No.</span></td>
-
<td><div align="center">:</div></td>
-
<td> <b><%=Session.Contents("IDNO")%></b></td>
-
</tr>
-
<tr>
-
<td><span class="style9">Sex</span></td>
-
<td><div align="center">:</div></td>
-
<td> <b><% =rsRetrieve("Sex")%></b></td>
-
</tr>
-
<tr>
-
<td> </td>
-
<td> </td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td colspan="3"><strong>This is to inform the school that my child/ward will be traveling to the following country/countries during the school holidays. The details are as listed below:</strong></td>
-
</tr>
-
</table>
-
<p class="style10"> </p>
-
-
<table width="583" align="center" height="91" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="583"><p class="style10"><strong>Important Notes:</strong></p>
-
<p class="style10"><strong>1. Where possible, please also provide details of country and date of transit if your child/ward will be stopping over at any other country while travelling.</strong></p>
-
<p class="style10"><strong>2. If your child/ward will not be traveling, please return the form with a NIL return.</strong></p></td>
-
</tr>
-
</table>
-
<p class="style10"> </p>
-
<table width="746" align="center" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="746"><p> </p>
-
<table width="639" align="center" border="1" cellpadding="3" cellspacing="2">
-
<tr>
-
<th width="282" rowspan="2" class="style9">Country of Intended Travel</th>
-
<th colspan="2" class="style9">Period of Stay</th>
-
</tr>
-
<tr>
-
<th width="151" class="style9">From</th>
-
<th width="151" class="style9">To</th>
-
</tr>
-
</table>
-
-
<table width="665" align="center" border="1" cellpadding="3" cellspacing="2" id="tblSample">
-
<tr>
-
<td colspan="6"><span class="style3">a</span></td>
-
</tr>
-
<%
-
-
Dim RetrieveArr(3)
-
-
coun = rsRetrieve("no_row")
-
-
for n = 1 to coun
-
-
//for each x in rsRetrieve.fields
-
for j = 0 to Ubound(all_fields)-1
-
Dim dbname
-
dbname = all_fields(j)
-
dbname = MID(dbname,5)
-
-
dbname = Replace(dbname,1,",")
-
dbname = Replace(dbname,",",n)
-
-
RetrieveArr(j) = rsRetrieve(dbname)
-
//response.write(dbname)&" " & RetrieveArr(j) &"<br>"
-
next
-
%>
-
<% if rsRetrieve("no_row") = 0 then %>
-
<tr>
-
-
<td width="12"><b> 1 </b></td>
-
<% else %>
-
<td width="17"><%=response.Write (n) %></td>
-
<% end if %>
-
<td width="255"><input type="text" name="txt_C1" id="txt_C1" size="40" onKeyPress="keyPressTest(event, this);" onBlur="javascript:Stud_Qual();" value="<%=RetrieveArr(0)%>" /></td>
-
-
<td width="144"><label>
-
<input type="text" name="txt_F1" id="txt_F1" onFocus="javascript:showCalendarControl(this);" value="<%=RetrieveArr(1)%>" readonly />
-
</label></td>
-
<td width="146"><label>
-
<input type="text" name="txt_T1" id="txt_T1" onFocus="javascript:showCalendarControl(this);" value="<%=RetrieveArr(2)%>" readonly />
-
</label></td>
-
<td width="27"><label>
-
<input name="btnDel" id="btnDel1" type="button" value="Delete" onClick="javascript:removeRowFromTable(this);">
-
</label></td>
-
</tr>
-
<%
-
//next
-
// i=i+1
-
// rsRetrieve.MoveNext
-
next
-
-
// next
-
%>
-
</table>
-
-
<p> </p>
-
-
<p align="center">
-
<input type="button" value="Add New Row" onClick="addRowToTable();" />
-
</p>
-
<p> </p>
-
</td>
-
</tr>
-
</table>
-
-
-
-
<table width="617" align="center" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="251" class="style9">Name of Parent/Guardian</td>
-
<td width="32" class="style9"><div align="center">:</div></td>
-
<td width="334" class="style9"><label>
-
<input type="text" name="tet_Name_PG" id="tet_Name_PG" value="<% =rsRetrieve("Name_PG")%>">
-
</label></td>
-
</tr>
-
<tr>
-
<td class="style9">Parent/Guardian contact No.</td>
-
<td class="style9"><div align="center">:</div></td>
-
<td class="style9"><label>
-
<input type="text" name="tet_Contact" id="tet_Contact" value="<% =rsRetrieve("Contact")%>" >
-
</label></td>
-
</tr>
-
</table> <p> </p>
-
<div align="center">
-
<input type="hidden" name="txt_count" id="txt_count" >
-
<input name="btnSave" type="button" value="Submit" onClick="javascript:validateRow(this.form);">
-
</div>
-
<p> </p> </td>
-
</tr>
-
</table>
-
-
-
</form>
-
<%
-
rsRetrieve.MoveNext
-
loop
-
End if
-
rsRetrieve.Close
-
my_Conn.Close
-
Set rsRetrieve = Nothing
-
Set my_Conn = Nothing
-
Response.Expires=-1
-
%>
-
<!--#include file="../MainMenu/Footer.htm" -->
-
-
<script>
-
setupScript();
-
</script>
-
-
Pls help me....
Thanks,
Susan.
29 5137
You have the following events: - el.onfocus = function(event){return removeRowFromTable(this);};
-
el.onkeypress = keyPressTest;
Surely you mean onclick and don't require the keypress event. I haven't checked the remove function(). What line does the error occur on and what is the exact error message?
Hi! - function removeRowFromTable(r)
-
{
-
var i=r.parentNode.parentNode.rowIndex; // pls check this line....
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
alert(i);
-
if (lastRow > 2 )
-
{
-
alert("i"+i);
-
tbl.deleteRow(i+1);
-
}
-
else
-
{
-
alert("Please enter 'NIL' for country if your are not travelling");
-
return;
-
}
-
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
//frm.action = "Remove_Data.asp";
-
//frm.submit();
-
}
If i delete the second row. alert msg say the value is 2, then If i delete the first row, alert msg say undefined value and automatically change the value is 0. why?
The value is changed 0, that time only display error. the error message is "Invalid argument". This is my problem. Pls help me.... Pls reply to me immediately.
Thanks and Regards,
Susan.
Can you show me the generated HTML code.
If there is an external JS link then post it also.
You are having table headers. And you want to delete all the rows except table headers. -
button_ref = function(){removeRow(this.parentNode.parentNode);}
-
...
-
...
-
-
function removeRow(row_ref){
-
row_ref.parentNode.removeChild(row_ref);
-
}
-
Hi!
Thankyou very much for reply.
I want to delete seleted rows and except row header. Now i problem is (If i delete the second row. alert msg say the value is 2, delete the forth row. alert msg say the value is 4. and If i delete the first row, alert msg say undefined value and change the value automatically is 0. why?) Kindly help me.... pls check my coding is below: -
function setupScript()
-
{
-
YesOnclick('travel', 'SPAN_travel', 'YES');
-
}
-
-
function displayNhide(display,status){
-
document.getElementById(display).style.display = status;
-
}
-
-
function YesOnclick(onClickbtn, spanId, valueToCheck){
-
var value = document.getElementById(onClickbtn).value;
-
alert(value);
-
-
if(value != 'NO' || value != 'NIL'){alert("VAlue" + value);
-
if(value == "YES")
-
displayNhide(spanId, 'block');
-
else
-
displayNhide(spanId, 'none');
-
}
-
-
}
-
-
-
<%pathdefiner = "../"%>
-
<!--#include file="../connection/connector.asp" -->
-
<!--#include file="declareVariables.asp" -->
-
<!--#include file="../MainMenu/Header.htm" -->
-
-
-
-
-
<script language="JavaScript" type="text/javascript">
-
<!--
-
var hasLoaded = false;
-
-
function addRowToTable()
-
{
-
var c=0;
-
// var nos=1;
-
// var i;
-
-
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;
-
//document.write ("iteration = " + iteration);
-
-
if(lastRow == 7)
-
{
-
alert("Only six countrys");
-
}
-
else{
-
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 = 'txt_C' + iteration;
-
el.id = 'txt_C' + iteration;
-
el.size = 40;
-
-
el.onkeypress = keyPressTest;
-
cellRight.appendChild(el);
-
-
-
// text box cell
-
var textRight = row.insertCell(2);
-
var el = document.createElement('input');
-
el.type = 'text';
-
el.name = 'txt_F' + iteration;
-
el.id = 'txt_F' + iteration;
-
el.onfocus = function(event){return showCalendarControl(this);};
-
el.size = 20;
-
el.onblur = this;
-
el.readOnly = this;
-
-
el.onkeypress = keyPressTest;
-
textRight.appendChild(el);
-
-
// text box cell
-
var txtRight = row.insertCell(3);
-
var el = document.createElement('input');
-
el.type = 'text';
-
el.name = 'txt_T' + iteration;
-
el.id = 'txt_T' + iteration;
-
el.onfocus = function(event){return showCalendarControl(this);};
-
el.size = 20;
-
el.onblur = this;
-
el.readOnly = this;
-
-
el.onkeypress = keyPressTest;
-
txtRight.appendChild(el);
-
-
// Delete Button
-
var btnRight = row.insertCell(4);
-
var el = document.createElement('input');
-
el.type = 'button';
-
el.name = 'btnDel' + iteration;
-
el.id = 'btnDel' + iteration;
-
el.value = 'Delete'
-
el.onfocus = function(event){return removeRowFromTable(this);};
-
el.onkeypress = keyPressTest;
-
btnRight.appendChild(el);
-
-
-
-
//Row count
-
lastRow = c+lastRow
-
document.frm.txt_count.value = lastRow;
-
-
}
-
}
-
-
function keyPressTest(e, obj)
-
{
-
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;
-
}
-
}
-
-
-
function removeRowFromTable(r)
-
{
-
var i=r.parentNode.parentNode.rowIndex;
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
alert(i);
-
if (lastRow > 2 )
-
{
-
alert("i"+i);
-
tbl.deleteRow(i);
-
}
-
else
-
{
-
alert("Please enter 'NIL' for country if your are not travelling");
-
return;
-
}
-
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
//frm.action = "Remove_Data.asp";
-
//frm.submit();
-
}
-
-
function onloa()
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
}
-
-
function validateRow(frm)
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
var i;
-
var compDate,j;
-
-
for (i=1; i<=lastRow; i++) {
-
var aRow = document.getElementById('txt_C' + i);
-
var FDate = document.getElementById('txt_F' + i).value;
-
var TDate = document.getElementById('txt_T' + i).value;
-
var country = document.getElementById('txt_C' + i).value;
-
-
country = country.toUpperCase();
-
-
-
if (aRow.value.length <= 0) {
-
alert('The country ' + i + ' is empty');
-
return;
-
}
-
var test;
-
test = "NIL"
-
compDate = TDate - FDate;
-
-
if (FDate>TDate) {
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
-
// else
-
if (country != test)
-
{
-
if(FDate == "NaN" || TDate == "NaN")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
-
else if(FDate == "" || TDate == "")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments.");
-
return;
-
}
-
}
-
-
-
// else
-
// {
-
// alert("Please enter the Date" + i);
-
// return;
-
// }
-
-
}// for loop end
-
-
if(document.getElementById('tet_Name_PG').value == "NIL" || document.getElementById('tet_Name_PG').value == "")
-
{
-
alert("Please enter Name of Parent/Guardian. ");
-
return;
-
}
-
-
var cons;
-
cons = document.getElementById('tet_Contact').value;
-
-
if (!Number(cons))
-
{
-
alert('Please enter Parent/Guardian Contact no.')
-
// frm.tet_Contact.focus();
-
return;
-
}
-
-
-
frm.submit();
-
}
-
-
function Stud_Qual()
-
{
-
if(document.getElementById("txt_C1").value == "NIL")
-
{
-
document.getElementById("txt_F1").value = document.getElementById("txt_C1").value;
-
document.getElementById("txt_T1").value = document.getElementById("txt_C1").value;
-
}
-
-
}
-
function MM_jumpMenu(targ,selObj,restore){ //v3.0
-
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
-
if (restore) selObj.selectedIndex=0;
-
}
-
//-->
-
</script>
-
<style type="text/css">
-
<!--
-
.style3 {
-
font-size: 1px;
-
color: #FFFFFF;
-
}
-
.style4 {
-
font-size: 24px;
-
font-weight: bold;
-
color: #003333;
-
}
-
.style9 {font-size: 18px; font-weight: bold; }
-
.style10 {color: #EE0000}
-
-->
-
</style>
-
-
<%
-
Dim retrieveSql, rSql
-
retrieveSql = "SELECT * FROM "& TBL_LOGIN & " WHERE " & TFL_IC & "='"& Session.Contents("IDNO") &"';"
-
-
Set rsRetrieve = Server.CreateObject("ADODB.Recordset")
-
Set rsRetrieve.ActiveConnection = my_Conn
-
-
rsRetrieve.Source = retrieveSql
-
rsRetrieve.Open
-
-
-
if rsRetrieve.EOF Then
-
else
-
do until rsRetrieve.EOF
-
%>
-
<form name="frm" id="frm" method="post" action="Update_Data.asp">
-
<table align="center" width="300" border="2" cellspacing="0" cellpadding="0" bordercolor="#004400" bgcolor="#e5ffe5">
-
<tr>
-
<td><img src="http://bytes.com/topic/javascript/images/overseas_travel5.jpg" width="872" height="242"></td>
-
</tr>
-
<tr>
-
<td>
-
<p> </p>
-
<p align="center" class="style4">INFORMING SCHOOL OF CHILD'S/WARD'S TRAVEL PLANS</p>
-
<p> </p>
-
-
<div align="center">
-
<p> </p>
-
<select name="travel" id="travel" onChange="javascript:YesOnclick('travel', 'SPAN_travel', 'YES')">
-
<option value="NIL">--Choose one--</option>
-
<option value="YES"> Travelling </option>
-
<option value="NO"> Not_Travelling </option>
-
</select>
-
-
<p> </p>
-
</label></div>
-
-
<table width="595" align="center" border="0" cellspacing="3" cellpadding="2">
-
<tr>
-
<td width="189"><span class="style9">Name of Child/Ward</span></td>
-
<td width="16"><div align="center">:</div></td>
-
<td width="334"> <b><% =rsRetrieve("Name")%></b></td>
-
</tr>
-
<tr>
-
<td><span class="style9">NRIC/FIN No.</span></td>
-
<td><div align="center">:</div></td>
-
<td> <b><%=Session.Contents("IDNO")%></b></td>
-
</tr>
-
<tr>
-
<td><span class="style9">Sex</span></td>
-
<td><div align="center">:</div></td>
-
<td> <b><% =rsRetrieve("Sex")%></b></td>
-
</tr>
-
<tr>
-
<td> </td>
-
<td> </td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td colspan="3"><strong>This is to inform the school that my child/ward will be traveling to the following country/countries during the school holidays. The details are as listed below:</strong></td>
-
</tr>
-
</table>
-
<p class="style10"> </p>
-
-
<table width="583" align="center" height="91" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="583"><p class="style10"><strong>Important Notes:</strong></p>
-
<p class="style10"><strong>1. Where possible, please also provide details of country and date of transit if your child/ward will be stopping over at any other country while travelling.</strong></p>
-
<p class="style10"><strong>2. If your child/ward will not be traveling, please return the form with a NIL return.</strong></p></td>
-
</tr>
-
</table>
-
<p class="style10"> </p>
-
<table width="746" align="center" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="746"><p> </p>
-
<table width="639" align="center" border="1" cellpadding="3" cellspacing="2">
-
<tr>
-
<th width="282" rowspan="2" class="style9">Country of Intended Travel</th>
-
<th colspan="2" class="style9">Period of Stay</th>
-
</tr>
-
<tr>
-
<th width="151" class="style9">From</th>
-
<th width="151" class="style9">To</th>
-
</tr>
-
</table>
-
-
<table width="665" align="center" border="1" cellpadding="3" cellspacing="2" id="tblSample">
-
<tr>
-
<td colspan="6"><span class="style3">a</span></td>
-
</tr>
-
<%
-
-
Dim RetrieveArr(3)
-
-
coun = rsRetrieve("no_row")
-
-
for n = 1 to coun
-
-
//for each x in rsRetrieve.fields
-
for j = 0 to Ubound(all_fields)-1
-
Dim dbname
-
dbname = all_fields(j)
-
dbname = MID(dbname,5)
-
-
dbname = Replace(dbname,1,",")
-
dbname = Replace(dbname,",",n)
-
-
RetrieveArr(j) = rsRetrieve(dbname)
-
//response.write(dbname)&" " & RetrieveArr(j) &"<br>"
-
next
-
%>
-
<% if rsRetrieve("no_row") = 0 then %>
-
<tr>
-
-
<td width="12"><b> 1 </b></td>
-
<% else %>
-
<td width="17"><%=response.Write (n) %></td>
-
<% end if %>
-
<td width="255"><input type="text" name="txt_C1" id="txt_C1" size="40" onKeyPress="keyPressTest(event, this);" onBlur="javascript:Stud_Qual();" value="<%=RetrieveArr(0)%>" /></td>
-
-
<td width="144"><label>
-
<input type="text" name="txt_F1" id="txt_F1" onFocus="javascript:showCalendarControl(this);" value="<%=RetrieveArr(1)%>" readonly />
-
</label></td>
-
<td width="146"><label>
-
<input type="text" name="txt_T1" id="txt_T1" onFocus="javascript:showCalendarControl(this);" value="<%=RetrieveArr(2)%>" readonly />
-
</label></td>
-
<td width="27"><label>
-
<input name="btnDel" id="btnDel1" type="button" value="Delete" onClick="javascript:removeRowFromTable(this);">
-
</label></td>
-
</tr>
-
<%
-
//next
-
// i=i+1
-
// rsRetrieve.MoveNext
-
next
-
-
// next
-
%>
-
</table>
-
-
<p> </p>
-
-
<p align="center">
-
<input type="button" value="Add New Row" onClick="addRowToTable();" />
-
</p>
-
<p> </p>
-
</td>
-
</tr>
-
</table>
-
-
-
-
<table width="617" align="center" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="251" class="style9">Name of Parent/Guardian</td>
-
<td width="32" class="style9"><div align="center">:</div></td>
-
<td width="334" class="style9"><label>
-
<input type="text" name="tet_Name_PG" id="tet_Name_PG" value="<% =rsRetrieve("Name_PG")%>">
-
</label></td>
-
</tr>
-
<tr>
-
<td class="style9">Parent/Guardian contact No.</td>
-
<td class="style9"><div align="center">:</div></td>
-
<td class="style9"><label>
-
<input type="text" name="tet_Contact" id="tet_Contact" value="<% =rsRetrieve("Contact")%>" >
-
</label></td>
-
</tr>
-
</table> <p> </p>
-
<div align="center">
-
<input type="hidden" name="txt_count" id="txt_count" >
-
<input name="btnSave" type="button" value="Submit" onClick="javascript:validateRow(this.form);">
-
</div>
-
<p> </p> </td>
-
</tr>
-
</table>
-
-
-
</form>
-
<%
-
rsRetrieve.MoveNext
-
loop
-
End if
-
rsRetrieve.Close
-
my_Conn.Close
-
Set rsRetrieve = Nothing
-
Set my_Conn = Nothing
-
Response.Expires=-1
-
%>
-
<!--#include file="../MainMenu/Footer.htm" -->
-
-
<script>
-
setupScript();
-
</script>
-
-
Pls reply to me immediately........ help me to solve....
Thanks & Regards,
Susan.
Well do one thing ... -
alert(r.tagName);
-
alert(r.parentNode.tagName);
-
alert(r.parentNode.parentNode.tagName);
-
Check all the Tag.
Hi!
alert(r.tagName); ----- i delete the second row. that time the alert message "INPUT", but delete the 3 row & if i delete the first row... that time the alert message is "INPUT" and delete the row header, didn't delete the first row...
alert(r.parentNode.tagName); ---- i delete the second row. that time the alert message "TD", but delete the 3 row & if i delete the first row... that time the alert message is "LABEL" and delete the row header, didn't delete the first row...
alert(r.parentNode.parentNode.tagName); ---- i delete the second row. that time the alert message "TR", but delete the 3 row & If delete the first row.... that time the alert message is "TD" and delete the row header, didn't delete the first row... why? pls help me...
i am not expert in javascript, so pls help me to solve this problem.
Thanks & Regards,
Susan.
@shivasusan
That's what exactly i expected ;)
so answer is already with you..simply remove the label around the INPUT delete button in the first row.
Please let me know what happens ;)
Hi!
Thankyou soooooo much.... it is working. i try to solve this more than one week, but today i got the answer with your help............ really thankyou... I am so happy..... thanks for you help immediately....:)
Yeah you welcome ;)
For that we are here ......
Hi!
I need one more help....
In the table i want to change the sl. no. automatically. How?
because If i delete the 3 row, the sl. no. is display (1,2,4,5,6.) wrongly. i want to display 1,2,3,4,5.
Thanks & Regards,
Susan.
see .................... suppose you want to delete nth row.
and you have m rows, where (m-1)>=n. -
function remove(...){
-
//delete the row
-
for(var i=n;i<m-1;i++){
-
var first_cell_ref = ...
-
first_cell_ref.innerHTML = i+1;
-
}
-
}
-
Hi!
Yes...
but in my program... i display the serial number in addrow() below my coding, so how i can change. If i change the remove(). its automatically change the serial number. sorry i am not understand.... -
var cellLeft = row.insertCell(0);
-
var textNode = document.createTextNode(iteration);
-
cellLeft.appendChild(textNode);
-
-
function removeRowFromTable(r)
-
{
-
var i=r.parentNode.parentNode.rowIndex;
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
alert(r.parentNode.tagName);
-
if (lastRow > 2 )
-
{
-
alert("i"+i);
-
tbl.deleteRow(i);
-
}
-
else
-
{
-
alert("Please enter 'NIL' for country if your are not travelling");
-
return;
-
}
-
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
document.frm.txt_count.value = lastRow;
-
-
//frm.action = "Remove_Data.asp";
-
//frm.submit();
-
}
Thanks & Regards,
susan.
Try this inside the remove function ... -
for(var k=i;k<lastRow-1;k++){
-
tbl.rows[k].cells[0].innerHTML = k+1;
-
}
-
Hi!
Thankyou soo much. I got the answer.
But i did little bit change. -
for(var k=i;k<lastRow-1;k++){
-
tbl.rows[k].cells[0].innerHTML = (k-1)+1;
-
}
-
-
Thanks & Regards,
Susan.
@shivasusan
Oh yeah...... That's right. What does it mean (k-1)+1, it means k.
Let the run time system to do operations as little as possible. Avoid unnecessary operation ;) Glad to see that you did that.
Hi!
I don't know how to change the other cells name?
for ex:(my table like this)
sl. country from to
1 aaa (txt_c1) 5/4/09 (txt_f1) 5/13/09 (txt_t1) // Now i delete this row.
2 bbb (txt_c2) 5/18/09 (txt_f2) 5/25/09 (txt_t2)
3 ccc (txt_c3) 6/2/09 (txt_f3) 6/15/09 (txt_t3) // now i delete this row.
4 eee (txt_c4) 7/15/09 (txt_f4) 7/25/09 (txt_t4)
Now the text box name is:
1 bbb (txtc_2) 5/18/09 (txt_f2) 5/25/09 (txt_t2) // here i want to change the text box name automatically (txtc_1, txtf_1, txtt_1) how?
2 eee (txtc_4) 7/15/09 (txt_f4) 7/25/09 (txt_t4) // here i want to change the text box name automatically (txtc_2, txt_f2, txt_t2) how?
I got this error in validateRow(). in for loop.... (txt_c+i)
sorry Sir/Madam, i don't know. how to change? pls help me. -
function validateRow(frm)
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
var i;
-
var compDate,j;
-
-
for (i=1; i<=lastRow; i++) {
-
var aRow = document.getElementById('txt_C' + i);
-
var FDate = document.getElementById('txt_F' + i).value;
-
var TDate = document.getElementById('txt_T' + i).value;
-
var country = document.getElementById('txt_C' + i).value;
-
var fieldvalue = document.getElementById("chk_travel").value;
-
-
country = country.toUpperCase();
-
-
-
if (aRow.value.length <= 0) {
-
alert('The country ' + i + ' is empty');
-
return;
-
}
-
var test;
-
test = "NIL"
-
compDate = TDate - FDate;
-
-
if (FDate>TDate) {
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments0.");
-
return;
-
}
-
-
-
// else
-
if (country != test)
-
{
-
if(FDate == "NIL" || TDate == "NIL")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments1.");
-
return;
-
}
-
-
else if(FDate == "" || TDate == "")
-
{
-
alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments2.");
-
return;
-
}
-
}
-
-
if(fieldvalue == "YES" && country == "NIL"){
-
alert("Please Enter the country name or If you are not Travel please select Not Travelling.");
-
return;
-
}
-
-
-
}// for loop end
-
-
-
if(document.getElementById('tet_Name_PG').value == "NIL" || document.getElementById('tet_Name_PG').value == "")
-
{
-
alert("Please enter Name of Parent/Guardian. ");
-
return;
-
}
-
-
var alphaExp = /^[a-zA-Z]+$/;
-
var pgname = document.getElementById('tet_Name_PG').value;
-
if(!pgname.match(alphaExp)){
-
alert("Please enter only characters");
-
return;
-
}
-
-
-
var cons;
-
cons = document.getElementById('tet_Contact').value;
-
-
if (!Number(cons))
-
{
-
alert('Please enter Parent/Guardian Contact no.')
-
// frm.tet_Contact.focus();
-
return;
-
}
-
-
if(fieldvalue == "NIL"){
-
alert("Please select Travelling or Not Travelling");
-
return;
-
}
-
-
frm.submit();
-
}
-
Thank & Regards,
Susan.
First of all why are you changing the name. Having the same name you can retrieve the values easily in server side.
Anyway... Updating the name is quite easy if you can change the serial no. -
for(var i=starting_row_num;i<current_row_nos_after_delete;i++){
-
var text_box_ref = .. ;
-
text_box_ref.name = 'text'+i;
-
}
-
Hi!
Thanks for you reply.
i try, but i am not understand.
i wrote this code in remove function. after delete its automatically change the text box name and id. (because my database field name is c1, f1, t1 to c6, f6, t6, so i want to change the field name c1,c2,c3....) pls help me....
now my doubt is:
1. how i can get the old text box name?
2. how i can change the new name for the text box?
3. i want to change the text box "name" and "id". -
-
for(var k=i;k<lastRow-1;k++){
-
-
tbl.rows[k].cells[0].innerHTML = (k-1)+1;
-
var aRow = document.getElementById('txt_C' + k);
-
var FDate = document.getElementById('txt_F' + k);
-
var TDate = document.getElementById('txt_T' + k);
-
-
aRow.name = ('txt_C' + k);
-
FDate.name = ('txt_F' + k);
-
TDate.name = ('txt_T' + k);
-
-
}
-
-
-
Thanks & Regards,
Susan.
@shivasusan
What's the problem with this? Do three elements alert you right object reference if you do alert(aRow+'\t'+FDate+'\t'+TDate)?
Why are you accessing those using IDs?
Simply you can go to the fields using rows[rowIndex].cells[cellIndex].childNodes[...].
Hi!
already i checked using alert. its didn't display anything in alert message. but i got error message. "aRow is null (aRow.name = ('txt_C' + k); " so i thought my coding is wrong and i understand wrongly. so i will ask you. how?
then i don't know any thing in rows[rowIndex].cells[cellIndex].childNodes[....]
pls help me... now what i can do? how i can solve this error? i did any wrong in my coding?
Thanks & Regards,
Susan.
@shivasusan
Try with ... -
var aRow = document.getElementById('txt_C' + (k+1));
-
var FDate = document.getElementById('txt_F' + (k+1));
-
var TDate = document.getElementById('txt_T' + (k+1));
-
I think that would work.
Hi!
sorry, still i didn't got the answer. today i want to finish this part, so pls help me....
the alert message display "null". I don't know, how to solve? -
for(var k=i;k<lastRow-1;k++){
-
-
var aRow = document.getElementById('txt_C' + (k+1));
-
var FDate = document.getElementById('txt_F' + (k+1));
-
var TDate = document.getElementById('txt_T' + (k+1));
-
-
tbl.rows[k].cells[0].innerHTML = (k-1)+1;
-
alert(aRow+'\t'+FDate+'\t'+TDate);
-
-
// aRow.name = ('txt_C' + k);
-
// FDate.name = ('txt_F' + k);
-
// TDate.name = ('txt_T' + k);
-
-
// tbl.rows[k].cells[1].childNodes[1].
-
}
-
-
change the sr. no. automatically coding below:
tbl.rows[k].cells[0].innerHTML = (k-1)+1;
how i can change the text box name for country, from and to? where i can place the aRow, FDate and TDate? But i try like this way, it is correct.
tbl.rows[k].cells[1].childNodes[1].
pls help i want to finish today itself. pls...
Thanks & Regards,
Susan.
Hi!
check the tagname "alert(r.parentNode.tagName); "
How i can check the textbox name?
@shivasusan
It should work, but i wonder why document.getElementById(..) is not working :(
Hi!
Yes.... its display null. pls give some idea. i want to finished this part today itself. so i feel very tension.
Hi
Now the alert message is "[object HTMLInputElement] [object HTMLInputElement] [object HTMLInputElement] " -
for(var k=i;k<lastRow-1;k++){
-
-
var aRow = document.getElementById('txtc' + (k+1));
-
var FDate = document.getElementById('txtf' + (k+1));
-
var TDate = document.getElementById('txtt' + (k+1));
-
-
tbl.rows[k].cells[0].innerHTML = (k-1)+1;
-
alert(aRow+'\t'+FDate+'\t'+TDate);
-
// aRow.name = ('txt_C' + k);
-
// FDate.name = ('txt_F' + k);
-
// TDate.name = ('txt_T' + k);
-
-
//alert(tbl.rows[k].cells[1].innerHTML);
-
}
-
-
this "alert(tbl.rows[k].cells[1].innerHTML);" --- <input size="40" id="txtc5 name=txtc5" type="Text">
pls give me some idea.
Thanks & Regards,
Susan.
@shivasusan
Perhaps that's the problem. The ID is actually "txtc5 name=txtc5", not "txtc5" as you would expect because of the missing quotes.
@acoder
But i think he fixed up this error. Now it alerts HTMLInputEelment.
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
1 post
views
Thread by Andrew DeFaria |
last post: by
|
2 posts
views
Thread by aiKeith |
last post: by
|
5 posts
views
Thread by lixiaoyao |
last post: by
|
1 post
views
Thread by Sandy |
last post: by
|
2 posts
views
Thread by Matt |
last post: by
| | | | | | | | | | | | | | |