/    Sign up×
Community /Pin to ProfileBookmark

how do I use a function with a database results

I have a database results that displays 3 text boxes across a table and as
many rows as the query returns. I have a function that will allow you to
enter a number in the first and second textbox then the function will add the numbers together and display it in the third textbox but it wont work if I
display more than one row. I need to know how to code the textboxes and
the function so It will increment the name values down the table here is a
sample of the function I am using
<script language=”javascript”>

function Totals() {
with (document.forms[“form1”])
{
var total1 = Number( box1.value ) + Number( box2.value );

box3.value = total1;

}
}
</script>

the html code is
<table border=”1″ width=”100%” id=”table1″>
<tr>
<td><input onblur=Totals() type=text name=box1 value=1></td>
<td><input onblur=Totals() type=text name=box2 value=1></td>
<td><input type=text name=sub_total value=”?” readonly onfocus=”this.blur()”></td>
<td>&nbsp;</td>
</tr>
<tr>
I dont show the database query that generates the rows
but I think box1 needs box1++1 or something. Please help if you can

Thanks
Dave

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@RobDavidFeb 21.2007 — Yes, you need to have all of your "boxes" named differently (including sub_total boxes).

You could pass these names as parameters to Totals()...

something like

function Totals(box1,box2,subTotal){

var frm = document.forms["form1"];

var total1 = Number( frm[box1].value ) + Number( frm[box2].value );

frm[subTotal].value = total1;


}
Copy linkTweet thisAlerts:
@davefedericiauthorFeb 21.2007 — I tried your sample code but could not get it to run yet. How would I give

different names to the boxes I dont know how records will be displayed

Thanks for your help
×

Success!

Help @davefederici spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...