Page 1 of 2
counting rows and colum
Posted: Thu Sep 15, 2011 5:03 pm
by johan
I'm trying to make something similar to your invoice system in the demo.
I tried to copy the code and JavaScript on the form but it doesn't work. My JavaScript in attach
What I hope to get as a result:
Every product got a unique code. I wan't to calculate the products with a code < 500 in subtot (1) and the products with code > 500 in (2).
In 1 (see attach) I wan't to calculate aantal * eenhprijs (code < 500)
In 2 i wan't to calculate aantal * eenhprijs (code > 500)
In A => I wan't the total of column 1
in B => the total of 2
In C => A - B
Thanks for helping me
Re: counting rows and colum
Posted: Fri Sep 16, 2011 7:27 pm
by johan
I'm still trying to get it to work. I looked ad tutorial 7 and made a form with subform with 3 text fields. (fd_aantal, fd_ep and fd_subtot) In the JavaScript I put this:
Code: Select all
function calclinetotal(pthis) {
PAGE = parent.frames[0] .document.forms[0];
PRE = pthis.name.substring(0,20);
aantal = Number(PAGE[PRE+'fd_aantal'].value);
eenhprijs = Number(PAGE[PRE+'fd_ep'].value);
subtot = "aantal * eenhprijs";
PAGE[PRE+ 'fd_subtot'].value = subtot;
NuFormat(PAGE[PRE+ 'fd_aantal']);
NuFormat(PAGE[PRE+ 'fd_ep']);
NuFormat(PAGE[PRE+ 'fd_subtot']);
}
In the
on blur of the 3 text items I got calclinetotal(this)
But I still don't get any result. Any idea what I'm doing wrong?
Re: counting rows and colum
Posted: Mon Sep 19, 2011 2:47 am
by admin
johan,
Firstly, take the quotes off
If that doesnt work put an alert between every step until you find out which step breaks.
(Its much easier to debug one line, than to look at everything at once)
Steven
Re: counting rows and colum
Posted: Mon Sep 19, 2011 9:53 am
by johan
Steven,
Thanks again for helping me out.
I removed the quotes but it still is'nt counting.
I get no error on my form. Everything works fine except the counting.
Sorry but I don't know much about javascript. How do I put an alert between every step?
I thought I could copy the code of tutorial 7 and replace the names of the columns where:
tri_quantity = fd_aantal
tri_price = fd_ep
tri_total = fd_subtot
Which database do you use in the tutorial? Is it on line?
Re: counting rows and colum
Posted: Tue Sep 20, 2011 12:23 am
by admin
johan,
javascript will just stop running if you have an error (and dont have script debugging on)
This means if you check to see if its running at certain points, its easier to figure out where a problem is.
an alert is a good way of doing this.
Capture.PNG
so you could perhaps do as I have below..
Code: Select all
function calclinetotal(pthis) {
PAGE = parent.frames[0] .document.forms[0];
PRE = pthis.name.substring(0,20);
alert(1);
aantal = Number(PAGE[PRE+'fd_aantal'].value);
eenhprijs = Number(PAGE[PRE+'fd_ep'].value);
alert(2);
subtot = "aantal * eenhprijs";
PAGE[PRE+ 'fd_subtot'].value = subtot;
alert(3);
NuFormat(PAGE[PRE+ 'fd_aantal']);
alert(4);
NuFormat(PAGE[PRE+ 'fd_ep']);
NuFormat(PAGE[PRE+ 'fd_subtot']);
}
Another way (and often even better - because you won't have to keep hitting OK), is to use nuDebug()
http://wiki.nubuilder.com/tiki-index.ph ... g_pString_.
Its used the same as alert() but gives results on a separate HTML page.
Give it a go.
And BTW, rather than using 1,2,3,4 try parsing the value you think you are getting eg. PAGE[PRE+ 'fd_ep']
Steven
Re: counting rows and colum
Posted: Tue Sep 20, 2011 9:56 am
by johan
Steven,
Or I'm doing something very stupid or ....
I tried alert() but nothing happens opening and editing my form.
I run nudebug and this is the output
Code: Select all
Debugging Output
function calclinetotal(pthis) { PAGE = parent.frames[0].document.forms[0]; PRE = pthis.name.substring(0, 20); aantal = Number(PAGE[PRE + "fd_aantal"].value); eenhprijs = Number(PAGE[PRE + "fd_ep"].value); subtot = aantal * eenhprijs; PAGE[PRE + "fd_subtot"].value = subtot; nuFormat(PAGE[PRE + "fd_aantal"]); nuFormat(PAGE[PRE + "fd_ep"]); nuFormat(PAGE[PRE + "fd_subtot"]); }
In nudebug I see that there are quotes around fd_aantal, fd_ep and fd_subtot. Could that be the reason? How can I remove them?
Re: counting rows and colum
Posted: Wed Sep 21, 2011 1:03 am
by admin
johan,
How do you know your function is working?
Trace your steps back to where you know something is working and then put an alert() after that.
If you dont know the answer to that, remove ALL the JavaScript from the Form you are working with, and start with some small bit of code you know will work, then gradually readd your code bit by bit code until you know where its stopping.
An alert or nuDebug are just tools to help you debug your code, just putting them in the middle of some code wont help.
If you dont know where a problem is "Divide and Conquer"
Steven
Re: counting rows and colum
Posted: Wed Sep 21, 2011 10:45 am
by johan
Steven,
My problem is that I know nothing about javascript. I'm trying to understand it but it's not easy.
I thought that making a copy of tutorial 7 would work but it does'nt work in my database. (strange)
In my database I made 3 fields fd_aantal, fd_ep, fd_subtot. First they where double(10,2) now I've changed them to float(7,2) as in nuvideo.
Putting alert(Page); returns [objectHTMLFormElement]
alert(PRE); returns fac_detail0000fd_ep, fac_detail0000fd_aantal, fac_detail0000fd_sub where fac_detail is the name of the table.
But what does that means? Is there an error in
Code: Select all
PAGE = parent.frames[0] .document.forms[0];
PRE = pthis.name.substring(0,20);
Why does it work in your tutorial and not for me?
Johan
Re: counting rows and colum
Posted: Thu Sep 22, 2011 7:14 am
by admin
johan,
Have you used any other programming languages?
Do you understand what document.getElementById() does?
I'm sorry I dont know where to start.
Steven
Re: counting rows and colum
Posted: Thu Sep 22, 2011 9:39 am
by johan
Steven,
sorry but
I know nothing about programming. I know something about mysql / postgreSQL and a little bit about php. That's why Nubuilder is so fantastic for me

.
But that's also the reason why I've tried to copy the JavaScript in tutorial 7 hoping it would work in my database. I still don't understand why I can't copy the code.
Johan