Hello all,
Thanks in ahead for any help you can give me. Basically I have an
order form with 10 product codes and 10 fields for quantity with the
name of the text field in each. What I am trying to do is put both the
quantities and products in an array and then loop through each one and
try and check if they are empty and also if they contain any bad
characters. These are the lines I am having the most trouble with
because they are not getting the right fields from the form.
q = quantities[i];
var quantity = document.account_edit.q.value;
<script language='javascript'>
function checkquantity() {
var quantities = new Array("qty1", "qty2", "qty3", "qty4", "qty5",
"qty6", "qty7", "qty8", "qty9", "qty10");
var prodnames = new Array("prodid1",
"prodid2","prodid3","prodid4","prodid5","prodid6","prodid7","prodid8","prodid9","prodid10");
//var quantity = document.account_edit.qty1.value;
var ql = quantities.length;
var pl = prodnames.length;
var blank_quantity = false;
var zen_quantity = false;
for(i = 0; i < ql; i++){
q = quantities[i];
var quantity = document.account_edit.q.value;
if(quantity.length == 0){
blank_quantity = true;
}
else if(isNaN(parseInt(quantity)) && quantity.length > 0){
zen_quantity = true;
}
}
if(blank_quantity){
alert('quantity is bad');
document.account_edit.action = '';
}
if(zen_quantity){
alert('quantity has bad characters in them');
document.account_edit.action = '';
}
}
David Mark - 31 Jul 2007 03:43 GMT
On Jul 30, 10:20 pm, ippatsu.ya...@gmail.com wrote:
> Hello all,
> Thanks in ahead for any help you can give me. Basically I have an
> order form with 10 product codes and 10 fields for quantity with the
Where?
> name of the text field in each. What I am trying to do is put both the
> quantities and products in an array and then loop through each one and
[quoted text clipped - 6 lines]
>
> <script language='javascript'>
type="text/javascript"
> function checkquantity() {
>
[quoted text clipped - 13 lines]
> q = quantities[i];
> var quantity = document.account_edit.q.value;
Change the above line to:
document.forms['account_edit'].elements[q].value
David Mark - 31 Jul 2007 03:46 GMT
[snip]
> Change the above line to:
>
> document.forms['account_edit'].elements[q].value
More specifically, change the right-hand side of the assignment.