Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

counting rows and colum

johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

counting rows and colum

Unread post 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
You do not have the required permissions to view the files attached to this post.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: counting rows and colum

Unread post 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?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: counting rows and colum

Unread post by admin »

johan,

Firstly, take the quotes off

Code: Select all

subtot = "aantal * eenhprijs";
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
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: counting rows and colum

Unread post 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?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: counting rows and colum

Unread post 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.

Code: Select all

alert(123);
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
You do not have the required permissions to view the files attached to this post.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: counting rows and colum

Unread post 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?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: counting rows and colum

Unread post 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
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: counting rows and colum

Unread post 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
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: counting rows and colum

Unread post 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
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: counting rows and colum

Unread post 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 :D .
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
Locked