rw1000
02-01-2007, 07:44 PM
Hello!
I try to build the dinamic form with JavaScript. On click event I need to add or remove one row from table. But Firefox do nothing, and IE is throw unknown exception :(
Please help me who can.
<div id="tbody">
<table class="odd" align="center" border="0" cellspacing="1">
<thead><tr><td>№</td><td>Value</td><td></td></tr></thead>
<tbody>
<tr nomer="111">
<td class="odd">111</td>
<td class="odd"><input size="30" name="value[111]" value="Author1" type="text"></td>
<td class="odd"><a href="#" onclick="return rmline(111);">Delete</a></td></tr>
<tr nomer="112">
<td>112</td>
<td><input size="30" name="value[112]" value="Author2" type="text"></td>
<td><a href="#" onclick="return rmline(112);">Delete</a></td></tr>
</tbody>
<tr><td colspan="3"><a href="#" onclick="return addline();">+ add row</a>
<input name="count" id="count" value="4" type="hidden"></td>
</tr>
</table>
</div>
<script language="JavaScript" type="Text/Javascript">
function addline(){
c=++document.getElementById('count').value;
// extract html of last row
s=document.getElementById('tbody').innerHTML;
s=s.replace(/[\r\n]/g,'');
re=/(.*)(<tr nomer=.*>)(<\/tbody>)/gi;
s1=s.replace(re,'$2');
// changing all numbers to new row number
s2=s1.replace(/\[\d+\]/gi,'['+c+']');
s2=s2.replace(/(rmline\()(\d+\))/gi,'$1'+c+')');
s=s.replace(re,'$1$2'+s2+'$3');
// updating html of table
document.getElementById('tbody').innerHTML=s;
return false;
}
function rmline(q){
s=document.getElementById('tbody').innerHTML;
s=s.replace(/[\r\n]/g,'');
//replace all html of needed row with space
re=new RegExp('<tr nomer="?\\['+q+'.*?<\\/tr>','gi');
s=s.replace(re,'');
document.getElementById('tbody').innerHTML=s;
return false;
}
</script>
I try to build the dinamic form with JavaScript. On click event I need to add or remove one row from table. But Firefox do nothing, and IE is throw unknown exception :(
Please help me who can.
<div id="tbody">
<table class="odd" align="center" border="0" cellspacing="1">
<thead><tr><td>№</td><td>Value</td><td></td></tr></thead>
<tbody>
<tr nomer="111">
<td class="odd">111</td>
<td class="odd"><input size="30" name="value[111]" value="Author1" type="text"></td>
<td class="odd"><a href="#" onclick="return rmline(111);">Delete</a></td></tr>
<tr nomer="112">
<td>112</td>
<td><input size="30" name="value[112]" value="Author2" type="text"></td>
<td><a href="#" onclick="return rmline(112);">Delete</a></td></tr>
</tbody>
<tr><td colspan="3"><a href="#" onclick="return addline();">+ add row</a>
<input name="count" id="count" value="4" type="hidden"></td>
</tr>
</table>
</div>
<script language="JavaScript" type="Text/Javascript">
function addline(){
c=++document.getElementById('count').value;
// extract html of last row
s=document.getElementById('tbody').innerHTML;
s=s.replace(/[\r\n]/g,'');
re=/(.*)(<tr nomer=.*>)(<\/tbody>)/gi;
s1=s.replace(re,'$2');
// changing all numbers to new row number
s2=s1.replace(/\[\d+\]/gi,'['+c+']');
s2=s2.replace(/(rmline\()(\d+\))/gi,'$1'+c+')');
s=s.replace(re,'$1$2'+s2+'$3');
// updating html of table
document.getElementById('tbody').innerHTML=s;
return false;
}
function rmline(q){
s=document.getElementById('tbody').innerHTML;
s=s.replace(/[\r\n]/g,'');
//replace all html of needed row with space
re=new RegExp('<tr nomer="?\\['+q+'.*?<\\/tr>','gi');
s=s.replace(re,'');
document.getElementById('tbody').innerHTML=s;
return false;
}
</script>