thanks for your advice Dom, you're making a lot of things clearer for
me
[color=blue]
> After looking at the code further I noticed a few more things. For your
> own interest I suggest placing doctype and character set definitions:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
>
> at the start of the document and validating it at:
>
http://validator.w3.org[/color]
I have done this, one thing I noticed was that I couldn't control the
size of my select boxes:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<SELECT id='test' name='test' style='width:50'>
<OPTION name='select one' value='' selected>
<OPTION name='1h_cmb_policy' value='YY10001878'>YY10001878
<OPTION name='1h_cmb_policy' value='YY10001884'>YY10001884
</OPTION>
</SELECT>
</body>
</html>
if I remove the first 2 lines from the code above, the select box will
become 50 pixels in width.
If I include the first 2 lines. the select box size is the width of
the longest string contained in it.
I tried adding the line:
"sel2.style.width ='100';"
after
rowSec2.id = 'row_' + globalClaimLnsRowNum;
cellSec2=document.createElement('TD');
and I had no problems.
Are the style.width used in createElement and the style='width:50' in
HTML much different commands?
I've been studying the code you used to restrict a loop to one row; by
copying the code from removeRow() into CalculateAll() I have tried and
failed to extract the row number or "TR" id
function calculateAll()
{
for( var node = this.parentNode; node; node=node.parentNode){
//if(node.tagName=="TR"){
//alert('node name and current row id: ' + node.Name);
//alert('node name and current row id: ' +
document.forms[0].elements.node.name);
//alert('node name and current row id: ' +
document.forms[0].elements[node].name);
//alert('node name and current row id: ' + node);
alert('node name and current row id: ' +
document.getElementById(node));
// }
}
calculateTab(2,globalClaimLnsRowNum);
}
I would expect that if "node" is an object, then it should have a
name. And I expected that name to be "row_1", "row_2" etc, from the
line:
"rowSec2.id = 'row_' + globalClaimLnsRowNum;"
am I mistaking "node" for an "element"? I have changed the attributes
of "TR" elements in the past using lines such as:
"document.getElementById(tdId).style.backgroundCol or = '#000000';"
With the "TBODY" element missing, the browser creates it. does that
mean before i was unnecesasarily creating a new "TBODY" element each
time the user clicks "Add Row"?
Memory dissipation is also halted by calling a function instead of
inserting the code into the elements onchange handler?
I need to find out more about nodes, apart from that it works great,
and is easier to understand now it is better laid out (below),
thanks again,
kie
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<html>
<head>
<meta name="Author" content="kie">
<meta name="Copyright" content="2003">
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css"
href="http://192.168.100.215/g-macs/lib/stylesheet.css">
<script>
<!--
// browser detection
// "InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;"
// This check is unreliable - apparently browsers forge the appName
value on a regular basis.
//
// checks should be made using the javascript that will be in the page
for certain safety
/**/
var s_browser = "";
// W3C & Netscape 6
if(document.getElementById) {
s_browser = "netscape6";
}
// browser is IE 4+:
else if (document.all) {
s_browser = "ie4";
}
// browser is Netscape 4+:
else if (document.layers) {
s_browser = "netscape4";
}
else {
s_browser = "";
}
//-->
</script>
<script type="text/javaScript" >
// JavaScript Document
// lib/js_functions.js - contents:
// setClaimID
// AllCheck_onclick
// mWillSave
// showHide
//calculateTab(3) used to calculate values in individual pages esp.
03_page.asp
<!--
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var globalChanged = false;
var globalNewRowChanged = false;
var globalClaimLnsRowNum = 1;
var isIE = false;
isIE = true;
function ex_amount(s_cur){
switch (s_cur)
{
case '1':
return '1.2';
break;
case '2':
return '0.6';
break;
case '3':
return '1.5';
break;
case '4':
return '2';
break;
case '5':
return '1';
break;
default:
return 0;
}
}
function detail_row(s_goods_id,s_unit_price,s_currency_id,s _quantity,s_uplift,s_total_line,s_incl_uplift,s_in cl_uplift_euro)
{
var body=document.body;
var Table,theRow,aCell,aTextBox,tablebody2,rowSec2;
var theTable;
var rowSec1,currenttext;
var opt1,sel2;
var cellSec1,cellSec2,cellSec3,cellSec4,cellSec5;
var cellSec6,cellSec7,cellSec8,cellSec9,cellSec10;
var formation = document.getElementById('formation');
var tablebody2=formation.getElementsByTagName('tbody')[0];
rowSec1=document.createElement('TR');
cellSec1=document.createElement('TD');
currenttext=document.createTextNode('Intitul');
rowSec2=document.createElement('TR');
rowSec2.id = 'row_' + globalClaimLnsRowNum;
cellSec2=document.createElement('TD');
sel2=document.createElement('select');
sel2.style.width ='100';
sel2.name='two_d_cmb_goods__' +
globalClaimLnsRowNum;
sel2.onchange=calculateAll;
opt1=document.createElement('option');
opt1.value='6';
if
(opt1.value==s_goods_id){opt1.setAttribute('select ed', true);}
opt1.innerHTML='Vacuum Cleaner';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='2';
if
(opt1.value==s_goods_id){opt1.setAttribute('select ed', true);}
opt1.innerHTML='Video Camera';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='1';
if
(opt1.value==s_goods_id){opt1.setAttribute('select ed', true);}
opt1.innerHTML='Video Recorder';
sel2.appendChild(opt1);
cellSec2.appendChild(sel2);
rowSec2.appendChild(cellSec2);
cellSec3=document.createElement('TD');
aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = nz(s_unit_price);
aTextBox.size = '10';
aTextBox.name = 'two_d_txt_unit_price__' +
globalClaimLnsRowNum;
aTextBox.onchange=calculateAll;
cellSec3.appendChild(aTextBox);
rowSec2.appendChild(cellSec3);
cellSec4=document.createElement('TD');
sel2=document.createElement('select');
sel2.name='two_d_cmb_currency__' +
globalClaimLnsRowNum;
sel2.onchange=calculateAll
opt1=document.createElement('option');
opt1.value='1';
if
(opt1.value==s_currency_id){opt1.setAttribute('sel ected', true);}
opt1.innerHTML='US$';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='2';
if
(opt1.value==s_currency_id){opt1.setAttribute('sel ected', true);}
opt1.innerHTML='£STG';
sel2.appendChild(opt1);
sel2.appendChild(opt1);
cellSec4.appendChild(sel2);
rowSec2.appendChild(cellSec4);
cellSec5=document.createElement('TD');
aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = nz(s_quantity);
aTextBox.size = '5';
aTextBox.name = 'two_d_txt_quantity__' +
globalClaimLnsRowNum;
aTextBox.onchange=calculateAll
cellSec5.appendChild(aTextBox);
rowSec2.appendChild(cellSec5);
cellSec6=document.createElement('TD');
aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = nz(s_total_line);
aTextBox.size = '5';
aTextBox.name = 'two_d_txt_total_line__' +
globalClaimLnsRowNum;
aTextBox.onchange=calculateAll
cellSec6.appendChild(aTextBox);
rowSec2.appendChild(cellSec6);
cellSec7=document.createElement('TD');
sel2=document.createElement('select');
sel2.name='two_d_cmb_uplift__' +
globalClaimLnsRowNum;
sel2.onchange=function(){calculateTab(2,globalClai mLnsRowNum);}
opt1=document.createElement('option');
opt1.value='100';
if
(opt1.value==s_uplift){opt1.setAttribute('selected ', true);}
opt1.innerHTML='100%';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='105';
if
(opt1.value==s_uplift){opt1.setAttribute('selected ', true);}
opt1.innerHTML='105%';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='110';
if
(opt1.value==s_uplift){opt1.setAttribute('selected ', true);}
opt1.innerHTML='110%';
sel2.appendChild(opt1);
opt1=document.createElement('option');
opt1.value='0';
if
(opt1.value==s_uplift){opt1.setAttribute('selected ', true);}
opt1.innerHTML='other';
sel2.appendChild(opt1);
cellSec7.appendChild(sel2);
rowSec2.appendChild(cellSec7);
cellSec8=document.createElement('TD');
aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = nz(s_incl_uplift);
aTextBox.size = '3';
aTextBox.name = 'two_d_txt_incl_uplift__' +
globalClaimLnsRowNum;
aTextBox.onchange=calculateAll
cellSec8.appendChild(aTextBox);
rowSec2.appendChild(cellSec8);
cellSec9=document.createElement('TD');
aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = nz(s_incl_uplift_euro);
aTextBox.name = 'two_d_txt_incl_uplift_euro__' +
globalClaimLnsRowNum;
aTextBox.size = '5';
aTextBox.onchange=calculateAll
cellSec9.appendChild(aTextBox);
rowSec2.appendChild(cellSec9);
cellSec10=document.createElement('TD');
ButtonSupprimer=document.createElement('input');
ButtonSupprimer.type = 'button';
ButtonSupprimer.value = 'remove';
ButtonSupprimer.onclick=removeRow;
cellSec10.appendChild(ButtonSupprimer);
rowSec2.appendChild(cellSec10);
tablebody2.appendChild(rowSec2);
formation.appendChild(tablebody2);
globalClaimLnsRowNum = globalClaimLnsRowNum + 1;
}
function calculateTab(n_tab_no,n_line_no){
var oForm = document.forms[0];
var n;
var t;
var a_ids = new Array;
var j=0;
switch (n_tab_no)
{
case 1: // header
break;
case 2: // detail
var s_cur = 0;
var n_uplift = 0;
var n_uplift_euro = 0;
if(s_browser = "ie4"){
fixFormBug(oForm)
}
// make array of ids were dealing with
for (i=0; i<oForm.elements.length; i++){
if(oForm.elements[i].name.indexOf("two_d_") == 0){
if(oForm.elements[i].name.indexOf("two_d_cmb_goods__") == 0){
n = oForm.elements[i].name.replace(/two_d_cmb_goods__/g,'');
a_ids[j] = n;
j = j+1;
}
}
}
// use array of ids to calculate all values in all rows
for (i=0; i<j; i++){
//alert(n_tab_no+' ' +n_line_no + ' ' + a_ids[i]);
oForm.elements['two_d_txt_total_line__' + a_ids[i]].value =
(parseFloat(nz(oForm.elements['two_d_txt_unit_price__' +
a_ids[i]].value)) * parseFloat(nz(oForm.elements['two_d_txt_quantity__'
+ a_ids[i]].value)));
oForm.elements['two_d_txt_incl_uplift__' + a_ids[i]].value =
(parseFloat(nz(oForm.elements['two_d_txt_total_line__' +
a_ids[i]].value)) * (parseFloat(nz(oForm.elements['two_d_cmb_uplift__'
+ a_ids[i]].value))/100));
oForm.elements['two_d_txt_incl_uplift_euro__' + a_ids[i]].value =
(parseFloat(oForm.elements['two_d_txt_incl_uplift__' +
a_ids[i]].value) * (ex_amount(oForm.elements['two_d_cmb_currency__' +
a_ids[i]].value)));
n_uplift = n_uplift + nz(oForm.elements['two_d_txt_incl_uplift__'
+ a_ids[i]].value);
n_uplift_euro = n_uplift_euro +
nz(oForm.elements['two_d_txt_incl_uplift_euro__' + a_ids[i]].value);
}
// if currencies are not all equal, cannot show sum of incl.
uplift, only sum of euro
for (i=0; i<j; i++){
if((s_cur != oForm.elements['two_d_cmb_currency__' +
a_ids[i]].value) & (s_cur != 0)){
n_uplift = 0
break;
}
s_cur = oForm.elements['two_d_cmb_currency__' + a_ids[i]].value;
}
// assign total values
oForm.elements['two_d_txt_detail_total'].value = nz(n_uplift);
oForm.elements['two_d_txt_detail_total_euro'].value =
nz(n_uplift_euro);
break;
case 3: // pay rec
break;
case 4: // banking
break;
case 5: // p uk
break;
default:
false;
}
}
function makeFieldUnionByName(oEls, name)
{
var result = null;
var resultArray = false;
for( var i = 0; i < oEls.length; ++i)
{
if( oEls[i].name!=name)
continue;
if( result && !resultArray)
{ result = [result];
resultArray = true;
}
if(resultArray)
result[result.length]=oEls[i];
else
result=oEls[i];
}
return result;
}
function fixFormBug(oForm) // Internet Explorer only
{
var oEls = oForm.elements;
var name;
for( var i = 0; i < oEls.length; ++i)
{
name = oEls[i].name;
if(name && !oForm[ name])
oForm[name] = makeFieldUnionByName(oEls,name);
}
}
function calculateAll()
{
for( var node = this.parentNode; node; node=node.parentNode){
//if(node.tagName=="TR"){
//alert('node name and current row id: ' + node.Name);
//alert('node name and current row id: ' +
document.forms[0].elements.node.name);
//alert('node name and current row id: ' +
document.forms[0].elements[node].name);
//alert('node name and current row id: ' + node);
alert('node name and current row id: ' +
document.getElementById(node));
// }
}
calculateTab(2,globalClaimLnsRowNum);
}
function removeRow() // method of form element within row
{
for( var node = this.parentNode; node; node=node.parentNode)
if(node.tagName=="TR")
break;
node.parentNode.removeChild(node);
calculateAll();
}
function nz(s_val){
var s_datatype = "undefined";
if(s_val==null || s_val=='' || isNaN(s_val) ||
typeof(s_val)==s_datatype){
//return isNaN(num)?0:num;
return 0;
}
else{
//alert(s_val);
return parseFloat(s_val);
}
}
function setLabel(objectId,s_label_name,is_element) {
if (is_element=='true'){
var n=document.all(objectId).length;
for(i=0;i<n;++i) {
if(document.all(objectId).options[i].selected) {
document.all(s_label_name).innerText =
document.all(objectId).options[i].text;
}
}
}else{
document.getElementById(s_label_name).innerHTML = objectId;
}
}
//-->
</script>
</HEAD>
<BODY>
<form method="post" action="" id="form_h" name="form_h">
<table>
<tr>
<td width='4%'>
<tr>
<td colspan='6'> </td>
</tr>
<tr>
<td> </td>
<td>
</td>
<td> </td>
<td colspan='1' align='right'> </td>
<td>
<input name='cmd_detail_new' type='button'
id='cmd_detail_new' value='ADD DETAIL [CLICK HERE]'
onclick=detail_row();>
</td>
<td> </td>
<td colspan='3' align='right'>DETAIL TOTAL / LOCAL </td>
<td>
<input name='two_d_txt_detail_total' type='text'
id='two_d_txt_detail_total' value='' size='10'>
</td>
<td width='16%'>=EUR</td>
<td width='30%'>
<input name='two_d_txt_detail_total_euro' type='text'
id='two_d_txt_detail_total_euro' value='' size='10'></td>
</td>
</tr>
<tr>
<td colspan='6'></td>
</tr>
</table>
</td>
</tr>
</table>
<table>
<tr>
<td height='20' valign='top'>
<table width='100%' border='1' cellpadding='0' cellspacing='0'
valign='top' id='formation'>
<thead>
<tr>
<td width='15%'> <b>GOODS</b></td>
<td width='5%'> <b>UNIT PRICE</b></td>
<td width='10%'> <b>CURRENCY</b></td>
<td width='5%'> <b>QUANTITY</b></td>
<td width='5%'> <b>TOTAL LINE</b></td>
<td width='5%'> <b>UPLIFT (%)</b></td>
<td width='5%'> <b>INCL. UPLIFT</b></td>
<td width='5%'> <b>=EUR</b></td>
<td width='5%'> <b> </b></td>
</tr>
<thead>
<tbody>
<tr>
<td colspan='10'>
<label id='label_detail'>NO RECORDS FOUND</label>
</td>
</tr>
</tbody>
<input type='hidden' id='two_d_txt_detail_ids'
name='two_d_txt_detail_ids' value=''>
<input type='hidden' id='txt_update_ids' name='txt_update_ids'
value=''>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>