David a écrit :
Stephane,
Many thanks for your promp help.
The checkboxes were just created in a simple html table.
The table must be in a form for better compatibility.
The JS with function init() gives to all checboxes an onclick event to
get immediately the new total when check/uncheck one of them.
The pop up works well, but the form does not close and the total value
is not passed back to my mainform ?
there was an error :-(
opener.document.forms[0].myTextArea.value = ...
---------^^^^^^^^^
Where is your mainform ?
has it a name ?
what is the name of your textarea ?
How do you open the popup ?
I do not require the '£' passed back, just the total sum, of which the
individual costs will always be whole numbers, i.e 10, 15, 25 etc
What do I need to do to get this working correctly
with the function add() as is, it would be OK
with/without '£' and with/without non decimal numbers
main file :
===========
<html>
<form name="myForm">
<textarea name="myTextArea" rows=10 cols=60></textarea>
</form>
<a href="#" onclick="window.open('tabauto.htm','','width=500,h eight=500');
return false;">open the popup</a>
</html>
popup file 'tabauto.htm' :
==========================
<html>
<script type="text/javascript">
function add() {
var t = document.getElementById('myTable');
t = t.getElementsByTagName('TBODY')[0];
t = t.rows;
var val = '';
var total = 0;
for(var i=1;i<t.length-1; i++) {
var c = t[i].getElementsByTagName('INPUT')[0];
var r = t[i].cells;
if(c.checked) {
val += r[0].innerHTML+' : '+
r[1].innerHTML.replace('£','')+'\n';
total += r[1].innerHTML.replace('£','')*1;
}
}
val += '-----------------------------\n'+
'TOTAL = '+total;
t[t.length-1].cells[1].innerHTML = total;
return val;
}
function valid() {
opener.document.myForm.myTextArea.value = add();
self.close();
}
function init() {
var t = document.getElementById('myTable');
t = t.getElementsByTagName('TBODY')[0];
t = t.rows;
for(var i=1;i<t.length-1; i++) {
var r = t[i].getElementsByTagName('INPUT');
r[0].onclick = function() { add(); }
}
}
window.onload = init;
</script>
<form action="" onsubmit="valid()">
<table id="myTable" border=1 celsspacing=2 width=70%>
<tr><th>Description</th><th>Charge</th><th>?</th></tr>
<tr><td>Item 1</td><td>10</td><td><input type=checkbox></td></td>
<tr><td>Item 2</td><td>12</td><td><input type=checkbox></td></td>
<tr><td>Item 3</td><td>20</td><td><input type=checkbox></td></td>
<tr><td>Item 4</td><td>50</td><td><input type=checkbox></td></td>
<tr><th colspan=2>Total = </th><th></th></tr>
</table>
<input type=submit value="OK">
</form>
</html>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date