HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 15th, 2009, 10:24 PM
wwiii wwiii is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 wwiii User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 41 sec
Reputation Power: 0
JavaScript - Dual validation

Hi
1st thx 4 ur time. 2nd i am not a coder of any kind. i consider myself a code editor. i do pretty well editing various codes to suit my needs. this is my 1st attempt to edit jscript other than a basic variable change.

i have a form that i need to validate in 2 ways but i can only get the validations to work one or the other not both.

i am pretty sure i need to combine them with an OR(||)statement or something simple but i am at a loss as to how to do it. i have spent 2 days researching and trial and error to no avail.

if u could help me out i would greatly appreciate it.

again thx for your time

this is as close as i have come to getting it to work so far

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="form_styles.css" />

<script type="text/javascript">
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  bbbits = document.BitsCrumblesMashForm.bbbits.value;
  bbcrumbles = document.BitsCrumblesMashForm.bbcrumbles.value;
  bbmash = document.BitsCrumblesMashForm.bbmash.value;
  bblastBox = document.BitsCrumblesMashForm.bblastBox.value;
  
  bsbits = document.BitsCrumblesMashForm.bsbits.value;
  bscrumbles = document.BitsCrumblesMashForm.bscrumbles.value;
  bsmash = document.BitsCrumblesMashForm.bsmash.value;
  bslastBox = document.BitsCrumblesMashForm.bslastBox.value;
  
  ffbits = document.BitsCrumblesMashForm.ffbits.value;
  ffcrumbles = document.BitsCrumblesMashForm.ffcrumbles.value;
  ffmash = document.BitsCrumblesMashForm.ffmash.value;
  fflastBox = document.BitsCrumblesMashForm.fflastBox.value;
  
  ppbits = document.BitsCrumblesMashForm.ppbits.value;
  ppcrumbles = document.BitsCrumblesMashForm.ppcrumbles.value;
  ppmash = document.BitsCrumblesMashForm.ppmash.value;
  pplastBox = document.BitsCrumblesMashForm.pplastBox.value;
  
  ssbits = document.BitsCrumblesMashForm.ssbits.value;
  sscrumbles = document.BitsCrumblesMashForm.sscrumbles.value;
  ssmash = document.BitsCrumblesMashForm.ssmash.value;
  sslastBox = document.BitsCrumblesMashForm.sslastBox.value;
  pkgsTotal = document.BitsCrumblesMashForm.pkgsTotal.value;
  
  bbprice = document.BitsCrumblesMashForm.bbprice.value;
  bsprice = document.BitsCrumblesMashForm.bsprice.value;
  ffprice = document.BitsCrumblesMashForm.ffprice.value;
  ppprice = document.BitsCrumblesMashForm.ppprice.value;
  ssprice = document.BitsCrumblesMashForm.ssprice.value;
  
  document.BitsCrumblesMashForm.bblastBox.value = (bbbits * 1) + (bbcrumbles * 1) + (bbmash * 1);
  document.BitsCrumblesMashForm.bslastBox.value = (bsbits * 1) + (bscrumbles * 1) + (bsmash * 1);
  document.BitsCrumblesMashForm.fflastBox.value = (ffbits * 1) + (ffcrumbles * 1) + (ffmash * 1);
  document.BitsCrumblesMashForm.pplastBox.value = (ppbits * 1) + (ppcrumbles * 1) + (ppmash * 1);
  document.BitsCrumblesMashForm.sslastBox.value = (ssbits * 1) + (sscrumbles * 1) + (ssmash * 1);
  document.BitsCrumblesMashForm.pkgsTotal.value = (bblastBox * 1) + (bslastBox * 1) + (fflastBox * 1) + (pplastBox * 1) + (sslastBox * 1);
  
  document.BitsCrumblesMashForm.bbprice.value = (bblastBox * 1) * (3.99 * 1);
  document.BitsCrumblesMashForm.bsprice.value = (bslastBox * 1) * (3.99 * 1);
  document.BitsCrumblesMashForm.ffprice.value = (fflastBox * 1) * (3.99 * 1);
  document.BitsCrumblesMashForm.ppprice.value = (pplastBox * 1) * (2.99 * 1);
  document.BitsCrumblesMashForm.ssprice.value = (sslastBox * 1) * (2.99 * 1);
  document.BitsCrumblesMashForm.ttlprice.value = (bbprice * 1) + (bsprice * 1) + (ffprice * 1) + (ppprice * 1) + (ssprice * 1);
}
function stopCalc(){
  clearInterval(interval);
}

validations Code:
Original - validations Code
    /* Checks Bits, Crumbles and MashQty Boxes - All Must be LESS than 12 */ function validate(){         x=document.BitsCrumblesMashForm         txt=(x.bbbits.value || x.bbcrumbles.value || x.bbmash.value || x.bsbits.value || x.bscrumbles.value || x.bsmash.value || x.ffbits.value || x.ffcrumbles.value || x.ffmash.value || x.ppbits.value || x.ppcrumbles.value || x.ppmash.value || x.ssbits.value || x.sscrumbles.value || x.ssmash.value)        if (!validate2()) { //validate the second way             alert("OOPS! Cakes MUST Equal 12")             return false;         }         if (txt < 12) {             return true         }else{             alert("OOPS! You have chosen 12 of something!")             return false         } } /* Checks sum of Total Packages Qty Box - Must equal 12 */ function validate2(){         x=document.BitsCrumblesMashForm         txt=x.pkgsTotal.value         if (txt!=12) {             return true         }else{             return false         }
} </script> <title>basic autosum</title> </head> <body> <form name="BitsCrumblesMashForm" action="http://www.aviancuisine.com/blog" onsubmit="return validate()" method="post"> <fieldset class="prod_selection"> <legend> Nutri-Bits, Crumbles and Mash Selections</legend> <br /> <div class="row"><span class="column_heading_bits">Bits</span> <span class="column_heading_crumbles">Crumbles</span><span class="column_heading_mash">Mash</span><span class="column_heading_pkgs">Pkgs</span><span class="column_heading_price">Price</span></div> <div class="row"><span class="label2">Bug Buffet</span><span class="formw5"> <input class="right" type=text name="bbbits" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="bbcrumbles" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="bbmash" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">=</span> <input class="right" type=text name="bblastBox" readonly="readonly" size="1"/> @ $3.99 ea = $ <input type=text name="bbprice" readonly="readonly" size="2"/> </span></div> <br /> <div class="row"><span class="label2">Broad Spectrum</span><span class="formw5"> <input class="right" type=text name="bsbits" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="bscrumbles" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="bsmash" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">=</span> <input class="right" type=text name="bslastBox" readonly="readonly" size="1"/> @ $3.99 ea = $ <input type=text name="bsprice" readonly="readonly" size="2"/> </span></div> <br /> <div class="row"><span class="label2">Fruit Feast</span><span class="formw5"> <input class="right" type=text name="ffbits" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="ffcrumbles" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="ffmash" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">=</span> <input class="right" type=text name="fflastBox" readonly="readonly" size="1"/> @ $3.99 ea = $ <input type=text name="ffprice" readonly="readonly" size="2"/> </span></div> <br /> <div class="row"><span class="label2">Peanut Paradise</span><span class="formw5"> <input class="right" type=text name="ppbits" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="ppcrumbles" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="ppmash" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">=</span> <input class="right" type=text name="pplastBox" readonly="readonly" size="1"/> @ $2.99 ea = $ <input type=text name="ppprice" readonly="readonly" size="2"/> </span></div> <br /> <div class="row"><span class="label2">Seed Sensation</span><span class="formw5"> <input class="right" type=text name="ssbits" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="sscrumbles" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">+</span> <input class="right" type=text name="ssmash" size="1" value="" onFocus="startCalc();" onBlur="stopCalc();"/> <span class="symbol">=</span> <input class="right" type=text name="sslastBox" readonly="readonly" size="1"/> @ $2.99 ea = $ <input type=text name="ssprice" readonly="readonly" size="2"/> </span></div> <br /> <div class="row"><span class="label2">Totals</span><span class="formw"> Pkgs <input type=text name="pkgsTotal" readonly="readonly" size="1"/> Price <input type=text name="ttlprice" readonly="readonly" size="2"/> </span></div> </fieldset> <br /> <input type="submit" value="Submit" id="button" name="button" /> </form> </body> </html>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > JavaScript - Dual validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
Stay green...Green IT