Forums

javascript for dynamic text...

mendk697 23 Aug, 2008
Hi,

Firstly, great component!

My question here is regarding a dynamic javascript form that will update input fields as the user enters values. The form works in HTML, but doesn't update the fields in Chronoforms. Here's a link to the form:

http://mediapedia.net/thebook/index.php?option=com_chronocontact&chronoformname=ofrm

And here's the code for the form that I am going to mod:
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Acme Widgets  - Get Your Widgets Here!</title>
<script language=javascript>
<!--//

function dm(amount) 
{
  string = "" + amount;
  dec = string.length - string.indexOf('.');
  if (string.indexOf('.') == -1)
  return string + '.00';
  if (dec == 1)
  return string + '00';
  if (dec == 2)
  return string + '0';
  if (dec > 3)
  return string.substring(0,string.length-dec+3);
  return string;
}



function calculate()
{

  QtyA = 0;  QtyB = 0;  QtyC = 0;
  TotA = 0;  TotB = 0;  TotC = 0;

  PrcA = 1.25; PrcB = 2.35; PrcC = 3.45;

 
 
  if (document.ofrm.qtyA.value > "")
     { QtyA = document.ofrm.qtyA.value };
  document.ofrm.qtyA.value = eval(QtyA);  
 
  if (document.ofrm.qtyB.value > "")
     { QtyB = document.ofrm.qtyB.value };
  document.ofrm.qtyB.value = eval(QtyB);  
 
  if (document.ofrm.qtyC.value > "")
     { QtyC = document.ofrm.qtyC.value };
  document.ofrm.qtyC.value = eval(QtyC);
 
 
  TotA = QtyA * PrcA;
  document.ofrm.totalA.value = dm(eval(TotA));
 
  TotB = QtyB * PrcB;
  document.ofrm.totalB.value = dm(eval(TotB));
 
  TotC = QtyC * PrcC;
  document.ofrm.totalC.value = dm(eval(TotC));
 
 
  Totamt = 
     eval(TotA) +
     eval(TotB) +
     eval(TotC) ;
    
  document.ofrm.GrandTotal.value = dm(eval(Totamt));
  
} 


//-->
</script>


</head>

<body bgcolor="#FFFFCC">

<h2>The Acme Widget Company</h2>
<h3>Get Your Widgets Here!</h3>
<br />
<p>Please make your selections from the following choices:</p>

<form method="POST" action="submitted.html" name="ofrm">
	<p>Please tell us who you are (<font color="#FF0000">red</font> denotes 
	required information):</p>
	<table border="0" cellpadding="0" width="550" id="table1">
		<tr>
			<td width="340" align="right"><font color="#FF0000">Name</font></td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="Name" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right"><font color="#FF0000">Email</font> 
			(Your confirmation will be sent here): </td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="Email" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right">Other Contact Info:</td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="OtherInfo" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right"> </td>
			<td width="10"> </td>
			<td width="200"> </td>
		</tr>
	</table>
	<p>And tell us what you would like:</p>
	<table border="0" cellpadding="0" width="550" id="table2">
		<tr>
			<td width="250" height="31"><b>Item Description</b></td>
			<td align="center" width="100" height="31"><b>Quantity</b></td>
			<td align="right" height="31" width="60"><b>Price </b></td>
			<td align="right" height="31" width="140"><b>Total</b></td>
		</tr>
		<tr>
			<td width="250">Class "A" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyA" size="5" tabindex="5" onchange="calculate()"></td>
			<td align="right" width="60">1.25</td>
			<td align="right" width="140">
			<input type="text" name="totalA" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250">Class "B" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyB" size="5" tabindex="5" onchange="calculate()"></td>
			<td align="right" width="60">2.35</td>
			<td align="right" width="140">
			<input type="text" name="totalB" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250">Class "C" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyC" size="5" tabindex="5" onchange="calculate()"></td>
			<td align="right" width="60">3.45</td>
			<td align="right" width="140">
			<input type="text" name="totalC" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250"> </td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140"> </td>
		</tr>
		<tr>
			<td width="250">
			<p align="right"><b>TOTALS:</b></td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140">
			<input type="text" name="GrandTotal" size="15" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250"> </td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140"> </td>
		</tr>
	</table>
	<p> </p>
	<table border="0" cellpadding="0" width="550" id="table3">
		<tr>
			<td width="563">
			<p align="center">
			<input type="submit" value="Submit" name="subButton" tabindex="50">     
			<input type="reset" value="Reset" name="resetButton" tabindex="50"></td>
		</tr>
	</table>
</form>

<p> </p>
<p>If you have questions or difficulties with this order page,<br />
 please contact 
our Customer Service Department (see our Contacts page.)</p>

</body>

</html>


Thanks in advance!

Best,
Karl
GreyHead 23 Aug, 2008
Hi mendk697,

When ChronoForms creates the form html it adds a 'ChronoContact_' prefix. You will need to use this long name if you want to reference the form name in your JavaScript. (from FAQ 03).

Probably the simplest approach is to define a variable in your JavaScript and use that in place of document.ofrm
var my_form = document.ChronoContact_ofrm;
. . .
 if (my_form.qtyA.value > "")
    { QtyA = my_form.qtyA.value };
 my_form.qtyA.value = eval(QtyA);
. . .

Bob
mendk697 24 Aug, 2008
sorry, I missed the FAQ! And thanks!
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger