yoshismokey
Programmer
I am having a problem accessing my cold fusion variables in a javascript function to validate the form fields.
Here is the cold fusion section where I am populating the form fields:
<form name="addfamily" action="AddUprForm.cfm" method="post" onSubmit="return CheckForm(this)">
<!--- Loop through the query and pull out the Product Families. --->
<cfoutput query="getinfo">
<tr>
<td align="center"><input type="Text" name="qty_#getinfo.Prod_Family_ID#" size="3" maxlength="5"></td>
<td width="266" valign="top" align="left"> <p> <font size="3" face="Arial, Helvetica, sans-serif" color="##C3046D"><strong>#getinfo.Prod_Family_Name#</strong></font></td>
<td align="center"><input type="text" name="discount_#getinfo.Prod_Family_ID#" size="3" maxlength="5">
%</td>
</tr>
</cfoutput>
And here is the javascript:
<script language="JavaScript">
<!--
//this function checks that if a quantity is entered,
//a discount is entered and vice versa
function CheckForm(form) {
var i, qty, discount;
var numproducts = 17;
for (i=1; i<numproducts; i++){
qty = "qty_" + i;
discount = "discount_" + i;
if (form.qty.value != "" && form.discount.value) == ""){
alert("You must enter a discount for each quantity entered");
return false;
}
else {
if (form.qty.value == "" && form.qty.value != ""){
alert("You must enter a quantity for each discount entered");
return false;
}
else {
return true;
}
}
}
}
</script>
The variables for quantity are qty_1 through qty_16; for discount - discount_1 through discount_16.
When I try to access the value in the fields by calling them qty_i and discount_i with i being the numbers 1 through 16, it doesn't work. What am I missing?
Thanks in advance,
Robin
Here is the cold fusion section where I am populating the form fields:
<form name="addfamily" action="AddUprForm.cfm" method="post" onSubmit="return CheckForm(this)">
<!--- Loop through the query and pull out the Product Families. --->
<cfoutput query="getinfo">
<tr>
<td align="center"><input type="Text" name="qty_#getinfo.Prod_Family_ID#" size="3" maxlength="5"></td>
<td width="266" valign="top" align="left"> <p> <font size="3" face="Arial, Helvetica, sans-serif" color="##C3046D"><strong>#getinfo.Prod_Family_Name#</strong></font></td>
<td align="center"><input type="text" name="discount_#getinfo.Prod_Family_ID#" size="3" maxlength="5">
%</td>
</tr>
</cfoutput>
And here is the javascript:
<script language="JavaScript">
<!--
//this function checks that if a quantity is entered,
//a discount is entered and vice versa
function CheckForm(form) {
var i, qty, discount;
var numproducts = 17;
for (i=1; i<numproducts; i++){
qty = "qty_" + i;
discount = "discount_" + i;
if (form.qty.value != "" && form.discount.value) == ""){
alert("You must enter a discount for each quantity entered");
return false;
}
else {
if (form.qty.value == "" && form.qty.value != ""){
alert("You must enter a quantity for each discount entered");
return false;
}
else {
return true;
}
}
}
}
</script>
The variables for quantity are qty_1 through qty_16; for discount - discount_1 through discount_16.
When I try to access the value in the fields by calling them qty_i and discount_i with i being the numbers 1 through 16, it doesn't work. What am I missing?
Thanks in advance,
Robin