Javascript validation question

I

ippatsu.yarou

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;
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;
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 = '';
}
}
 
D

David Mark

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
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;
var quantity = document.account_edit.q.value;

<script language='javascript'>
type="text/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","prod­id9","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;
var quantity = document.account_edit.q.value;


Change the above line to:

document.forms['account_edit'].elements[q].value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top