Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / July 2007



Tip: Looking for answers? Try searching our database.

Javascript validation question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ippatsu.yarou@gmail.com - 31 Jul 2007 03:20 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.