473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form Data Help

Hi,

I have a MAINFORM with a pop-up form link and a textfield

The POPUPFORM displays 3 columns

(1) Description : (2) £Charge : (3) Checkbox

Each charge will be different for the various descriptions.
A user needs to be able to select from 1 or more checkboxes then press
submit.
When the form is submitted, the form/page is closed and the charges
for each item selected are totalled and dumped into a textfield on the
MAINFORM.

I have the Mainform and the Popupform, but do not know how to take all
the selected values (from column 'x' , total them and put the total in
the textfield on the Mainform ?

I would appreciate any help you could offer

Thanks

David

May 29 '07 #1
4 1507
ASM
David a écrit :
Hi,

I have a MAINFORM with a pop-up form link and a textfield

The POPUPFORM displays 3 columns
what do you mean by columns ? are they cells of a table ?
(1) Description : (2) £Charge : (3) Checkbox

Each charge will be different for the various descriptions.
A user needs to be able to select from 1 or more checkboxes then press
submit.
When the form is submitted, the form/page is closed and the charges
for each item selected are totalled and dumped into a textfield on the
MAINFORM.

I have the Mainform and the Popupform, but do not know how to take all
the selected values (from column 'x' , total them and put the total in
the textfield on the Mainform ?

I would appreciate any help you could offer
In your popup :

<script type="text/javascript">

function add() {
var t = document.getElementById('myTable');
t = t.getElementsByTagName('TBODY')[0];
t = t.rows;
var val = '', 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;
}
function valid() {
add();
opener.forms[0].myTextArea.value = val;
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>Checkbox</tr>
<tr><td>Item 1</td><td>£1.25</td><td><input type=checkbox></td></td>
<tr><td>Item 2</td><td>£2.25</td><td><input type=checkbox></td></td>
<tr><td>Item 3</td><td>£3.05</td><td><input type=checkbox></td></td>
<tr><td>Item 4</td><td>£10.25</td><td><input type=checkbox></td></td>
<tr><th colspan=2>Total = </th><th></th></tr>
</table>
<input type=submit value="OK">
</form>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
May 29 '07 #2
Stephane,

Many thanks for your promp help.
The checkboxes were just created in a simple html table.
The pop up works well, but the form does not close and the total value
is not passed back to my mainform ?
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

Many thanks

David
---------------------------------------------------------------------------------------------------
In your popup :

<script type="text/javascript">

function add() {
var t = document.getElementById('myTable');
t = t.getElementsByTagName('TBODY')[0];
t = t.rows;
var val = '', 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;}

function valid() {
add();
opener.forms[0].myTextArea.value = val;
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>Checkbox</tr>
<tr><td>Item 1</td><td>£1.25</td><td><input type=checkbox></td></td>
<tr><td>Item 2</td><td>£2.25</td><td><input type=checkbox></td></td>
<tr><td>Item 3</td><td>£3.05</td><td><input type=checkbox></td></td>
<tr><td>Item 4</td><td>£10.25</td><td><input type=checkbox></td></td>
<tr><th colspan=2>Total = </th><th></th></tr>
</table>
<input type=submit value="OK">
</form>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date

May 29 '07 #3
ASM
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
May 29 '07 #4
Stephane,

I have tried your fixed code, but to no avail.
If I set my Textfield to the function = add(); I get the following
loaded into my textfield on the original mainform: Item 1 : 10
It only loads 1 selection, always the first, even when multiple items
are selected. It does not calculate any total when loading the
tetxfield. If I change = = add(); to = "test string"; then 'test
string' gets loaded into my textfield. I cannot find any variable or
function that holds the calculated total to return that value to my
textfield ?

I have just tried your code in IE rather than Firefox and found the
following data was loaded:
Item 1 : 10Item 2 : 12-----------------------------TOTAL = 22

I will now try and get this to work so that only the total '22' is
sent back.

So, is there a way to make this code work in FF ?

Thanks David

On 29 May, 16:56, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
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

May 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: cooldv | last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this code: message = Replace(usermessage, "'", "''"). My problem is DISPLAYING data in an asp FORM, from an an access database,...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
2
by: PinkBishop | last post by:
Hello All, Hope you can help. Below is the code I use to send data from form to database. Problem is if an apostrophe is entered in cQuestion field or any field for that matter the form...
3
by: Kathy | last post by:
Can someone help me with the code to take the data in four fields on an HTML form and add it to a table in a database on an intranet. Thanks to all who help! Kathy
3
by: Earthling | last post by:
Any help would be appreciated to solve the following simple problem that I will describe. *** There is a form called "red chocolate form". The form has a particular subform field that has a...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
2
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
4
by: Cerebral Believer | last post by:
Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.