Gossamer Forum
Home : Products : DBMan : Customization :

Adding two fields in a database.

Quote Reply
Adding two fields in a database.
Basically I would like a DB man databse to add/multiply two fields together, and pout the result in a thrid field. This field being updated automatically if eithe rvalue is changed etc.

How do I do this?

Dan
Quote Reply
Re: Adding two fields in a database. In reply to
Hello Dan:

Because Perl only works on the server side, you cannot use Perl or cgi programs to update things automatically without submitting by pressing a submit button.
And because you want automatic update and don't want to press submit button to get the result, what I would suggest is to use JavaScript.

You can embed JavaScript in the html subroutines. There ia an event called onChange in JavaScript that when something changes, it automatically updates the other values. This is client-side as opposed to server-side.

If you want to learn more about javascript, I recommend you to go to http://www.javascript.com or the MSDN online.


------------------
-------------------- Gossamer Threads Inc. ----------------------
Sun Djaja Email: sun@gossamer-threads.com
Internet Consultant
http://www.gossamer-threads.com

Quote Reply
Re: Adding two fields in a database. In reply to
You would need to add code to both sub add_record and sub modify_record in db.cgi.

In both subroutines, just after the "my" line at the top of the subroutine--

sub add_record {
my ($output, $status, $counter);


sub modify_record {
my ($status, $line, @lines, @data, $output, $found, $restricted);

add

$in{'ComputedValue'} = $in{'Value1'} + $in{'Value2'};

Of course, you will need to change the field names to match your .cfg file.

You can also use

$in{'ComputedValue'} = $in{'Value1'} * $in{'Value2'};

$in{'ComputedValue'} = $in{'Value1'} - $in{'Value2'};

$in{'ComputedValue'} = $in{'Value1'} / $in{'Value2'};

but be careful about using division. You have to be certain that $in{'Value2'} will be greater than 0 or you'll get an error.


------------------
JPD





Quote Reply
Re: Adding two fields in a database. In reply to
I guess sun and I had a different interpretation of what Dan meant by "automatically." Smile

------------------
JPD