...

View Full Version : how do I use a function with a database results



davefederici
02-20-2007, 06:26 PM
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

Akimoto°
02-23-2007, 01:44 AM
I am a newbie in Javascript and have made somthing similar.. :eek:

<head></head>

<script language="JavaScript">
<!--
function temp(form)
{
var f = parseFloat(form.box1.value, 0);
var g = parseFloat(form.box2.value, 0);
var c = 0;
c = f + g;
form.box3.value = c;
}
//-->
</script>

<body></body>


<FORM>
<INPUT NAME="box1" VALUE="0" MAXLENGTH="15" SIZE=15>
+
<INPUT NAME="box2" VALUE="0" MAXLENGTH="15" SIZE=15>
<INPUT VALUE="=" TYPE=BUTTON onClick=temp(this.form)>
<INPUT NAME="box3" READONLY SIZE=15>
</FORM>

Here is an example of what it would look like. (http://ogame.akikun.com/example_1.htm)

I used a different form of coding on this one. But i beleve the result is the same you are looking for. (I hope)


EDIT:

Noticed the frame part. Personally, i learn best when studying complete scripts rather than having to search online not knowing what to search after.

Example Frames (http://ogame.akikun.com/example_2.htm)



<html>
<head>
<script language="JavaScript">
<!--
function temp1(form)
{
var f = parseFloat(form.box1.value, 0);
var g = parseFloat(form.box2.value, 0);
var c = 0;
c = f + g;
form.box3.value = c;
}
function temp2(form)
{
var f = parseFloat(form.box13.value, 0);
var g = parseFloat(form.box23.value, 0);
var c = 0;
c = f + g;
form.box33.value = c;
}
function temp3(form)
{
var f = parseFloat(form.box12.value, 0);
var g = parseFloat(form.box22.value, 0);
var c = 0;
c = f + g;
form.box32.value = c;
}
//-->
</script>
</head>
<body>
<FORM>
Visible Frames: <br>
<br>
<table width="123" border="1" cellpadding="0" cellspacing="0">
<tr>
<th width="27" scope="row">&nbsp;</th>
<td width="90"><input name="box1" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row">+</th>
<td><input name="box2" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row"><input name="BUTTON" type=BUTTON onClick=temp1(this.form) value="="></th>
<td><input name="box3" value="?" size=15 readonly></td>
</tr>
</table>
<br>
<br>
Even more visible frames:<br>
<br>
<table width="123" border="1">
<tr>
<th width="27" scope="row">&nbsp;</th>
<td width="90"><input name="box13" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row">+</th>
<td><input name="box23" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row"><input name="BUTTON3" type=BUTTON onClick=temp2(this.form) value="="></th>
<td><input name="box33" value="?" size=15 readonly></td>
</tr>
</table>
<br>
<br>
Invisible Frames:<br>
<br>
<table width="131" border="0">
<tr>
<th width="25" scope="row">&nbsp;</th>
<td width="90"><input name="box12" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row">+</th>
<td><input name="box22" value="0" maxlength="15" size=15></td>
</tr>
<tr>
<th scope="row"><input name="BUTTON2" type=BUTTON onClick=temp3(this.form) value="="></th>
<td><input name="box32" value="?" size=15 readonly></td>
</tr>
</table>
</FORM>
</body>
</html>


Hmm...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum