Link to home
Start Free TrialLog in
Avatar of cmsRuncorn
cmsRuncorn

asked on

How to create function to add two text boxes together

Hi experts, please can someone help me with a problem im encountering. Basically i have a page which shows various figures for different currencies, i have just added in three extra text boxes (txtprefamount, txtaddamount, txttotal), and what i want to do is to create a function to add together the values from txtprefamount and txtaddamount and put the total in txttotal, the problem is that im pulling the currency symbols from sql and thus it create's the text boxes indvidually and i need to calculate the two figures individually for each currency. I know this should be simple enough but im a bit of a novice when it comes to functions. Any help is appreciated. Thanks
<TABLE border=0 cellpadding=0 cellspacing="4" width="40%">
	<tr bgcolor="#CC6600">
		<td colspan=3 width="100%"><font size="2"><img src="images/blank.gif" width="8" height="1"></font></td>
	</tr>
<p>&nbsp;</p>
      <tr> 
               
	
		<TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2">Currency</font></TD>
        <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2">Recommended Amount</font></TD>
        <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2">Prepared Amount</font></TD>
        <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2">Additional Amount</font></TD>
        <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2">Total Sell Off</font></TD>
	
      </tr>
      <tr bgcolor="#CC6600">
		<td colspan=3 width="100%"><font size="2"><img src="images/blank.gif" width="8" height="1"></font></td>
	</tr>
	    <tr>
	    
	    <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Main Currencies</b></font></TD>
	    </tr>
      <%
      rsType.movefirst
      do until rsType.eof
		iDefaultCashCentre  = rsType("SellOffCashCentre")
      %>
      <tr>
 
        <td width="50%" bgcolor="#FFFFFF">
			<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><%=rsType("currencysymbol")%>
				<input type=hidden name="txtsym<%=CurrInt%>" maxlength="10%" size="22%" value="<%=rsType("currencysymbol")%>">
				<input type=hidden name="txtCurrency<%=CurrInt%>" maxlength="10%" size="22%" value="<%=rsType("SellOffCurrency")%>">
			</font>
		</td>
        <td width="50%" bgcolor="#FFFFFF"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399">
        <input name=txtCash<%=CurrInt%> maxlength="9"
		<%if rsType("SellOffStatus") = "Sent" then%> 
			value="0" 
        <%else%>
			value="<%=rsType("SellOffacAmount")%>" 
        <%end if%> 
		size="22%"></font>
		<input type=hidden name=txtStatus<%=CurrInt%> value="<%=rsType("SellOffStatus")%>">
 
		</td>
			<input type=hidden name="lstCashCentre<%=CurrInt%>" value=<%=arrCashCentre(0,0)%>>
		
		<input type=hidden name="lstMinSellOff<%=CurrInt%>" value=<%=rsType("minSellOff")%>>
	    <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txtprefamount onChange="javascript:add()"/></font>
      </td>
        <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txtaddamount onChange="javascript:add()"/></font>
      </td>
      <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txttotal onChange="javascript:add()"/></font>
      </td>
      </tr>
<%
CurrInt=CurrInt+1
rsType.MoveNext
loop
%>
 
<tr bgcolor="#CC6600">
		<td colspan=3 width="100%"><font size="2"><img src="images/blank.gif" width="8" height="1"></font></td>
	</tr>
	    <tr>
	    
	    <TD bgColor=#ffffff width="50%"><font color="#00599d" face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Exotic Currencies</b></font></TD>
	    </tr>
      <%
      rsOther.movefirst
      do until rsOther.eof
		iDefaultCashCentre  = rsOther("SellOffCashCentre")
      %>
      <tr>
 
        <td width="50%" bgcolor="#FFFFFF">
			<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><%=rsOther("currencysymbol")%>
				<input type=hidden name="txtsym<%=CurrInt%>" maxlength="10%" size="22%" value="<%=rsOther("currencysymbol")%>">
				<input type=hidden name="txtCurrency<%=CurrInt%>" maxlength="10%" size="22%" value="<%=rsOther("SellOffCurrency")%>">
			</font>
		</td>
        <td width="50%" bgcolor="#FFFFFF"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399">
        <input name=txtCash<%=CurrInt%> maxlength="9"
		<%if rsOther("SellOffStatus") = "Sent" then%> 
			value="0" 
        <%else%>
			value="<%=rsOther("SellOffacAmount")%>" 
        <%end if%> 
		size="22%"></font>
		<input type=hidden name=txtStatus<%=CurrInt%> value="<%=rsOther("SellOffStatus")%>">
 
		</td>
			<input type=hidden name="lstCashCentre<%=CurrInt%>" value=<%=arrCashCentre(0,0)%>>
		
		<input type=hidden name="lstMinSellOff<%=CurrInt%>" value=<%=rsOther("minSellOff")%>>
	   <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txtprefamount onChange="javascript:add()"/></font>
      </td>
        <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txtaddamount onChange="javascript:add()"/></font>
      </td>
      <td>
		<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003399"><input type=text value=0 name=txttotal onChange="javascript:add()"/></font>
      </td>
      </tr>
      </tr>
<%
CurrInt=CurrInt+1
rsOther.MoveNext
loop
%>

Open in new window

Avatar of HonorGod
HonorGod
Flag of United States of America image

Currently, you have/use:

<input type=text value=0 name=txtprefamount onChange="javascript:add()"/>
<input type=text value=0 name=txtaddamount onChange="javascript:add()"/>
<input type=text value=0 name=txttotal onChange="javascript:add()"/>

You probably want to make txttotal as readonly, without the onChange (the user shouldn't be specifying the total).

It would also be easier/better if you used the id attribute, instead of the name attribute for these fields, since the id attribute is supposed to be unique on the page, whereas elements that are to be grouped together can, and should share the same name.

How will the numeric values look?

What unit separators can & will exist?

Where will the currency characters be placed?

Can currency characters be empty, or must they be present?
Avatar of cmsRuncorn
cmsRuncorn

ASKER

Thanks for your reply, and i shall change the txttotal field to read only as that makes more sense.
As for the id attribute, i can't say i've used it before so i would be unaware of the syntax but again that does sound better than using the name tag.

The numeric values will have no seperators and will be to 1 decimal place so no format change is required i think. The  currency characters are actually currency names which show up as shortnames for the currencies (i.e. EUR for Euro and GBP for Pound Sterling etc...). The currency names must be there as this page will be an ordering page and they are the unique identifier.

Please find attached a cropped example of the page, this shows the main currencies, the exotic currencies are just below (but wouldn't fit on!) , the page loops through the sql string and pulls back all requested currencies. I hope this clarifies things a bit more and thanks for the help


example.jpg
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, thanks for the reply, i have implemented what you suggested and it only works on the first line, the rest of the currencies do no do anything? So if you look at the example the top row calculates correctly but all the rows below do nothing.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What else needs to be done for you with respect to this question?
Thanks a lot for all your help, that's exactly what i needed.
Thanks for the grade & points.

Good luck & have a great day.