?
Solved

how to restrict form selections based on user entry validations

Posted on 2003-02-21
6
Medium Priority
?
226 Views
Last Modified: 2006-11-17
Hi,

I am trying to create a JavaScript lease calculator script. When a user selects wthin a given constraint it should restrict the selection of other options.
For example, a user enters a lease amount between 5000 to 300000. If the amount entered is between 5000 and 100000 then the lease approval could be obtained by a credit approval process.
If the lease amount were between 50000 and 300000 approval could be obtained by a financials approval process.
Leases less than 50000 would be invalid for financials approval and leases more than 100000 would be invalid for credit approval.
The following .js is what I have so far. Any help would be greatly appreciated.



function checkInt()
{
     temp = window.event.keyCode;
     //alert (temp)
     if ( (temp >= 48 ) && (temp<= 57)  )
     {
          //alert(temp);
          window.event.keyCode = temp;
     }
     else
     {
          window.event.keyCode = "";
     }

}

function checkDecimalValue()
{
     temp = window.event.keyCode;
     //alert (temp)
     if (( (temp >= 48 ) && (temp<= 57) ) || (temp<= 46) )
     {
          //alert(temp);
          window.event.keyCode = temp;
     }
     else
     {
          window.event.keyCode = "";
     }

}


function checkRange()
{
     temp = window.document.LeaseForm.txtLeaseAmount.value;
     
     if ( (temp<5000) || (temp>300000) )
     {    
          alert("Lease Amount must be greater than $5000 and less than $300000.");          
          window.document.LeaseForm.txtLeaseAmount.focus();
          window.document.LeaseForm.txtLeaseAmount.select();          
     }
     else
     {
         
          //alert(temp);
          //Credit based Approval
          if( (temp >=5000) && (temp <= 100000) )
          {
               //window.document.LeaseForm.cmbApprovalProcess.value = "Credit Approval";
          }
         
         
         
          //Financials based Approval
          if( (temp > 100000) && (temp <= 300000) )
          {
               //window.document.LeaseForm.cmbApprovalProcess.value = "Financial Approval";
          }          
     }
}

function validString()
{
     temp = window.event.keyCode;
     //alert(temp);
     
     if ( (temp == 32 ) || ( (temp >= 65) && (temp <= 90) ) || ( (temp >= 97) && (temp <= 122) ) )
     {
          //alert(temp);
          window.event.keyCode = temp;
     }
     else
     {
          window.event.keyCode = "";
     }

}

function checkApprovalProcess()
{
     
     
     
     alert("checkApprovalProcess");
}

function validate()
{
if (document.LeaseForm.strEmail.value == "" )
     {    
          alert("You cannot leave email field empty.");          
          document.LeaseForm.strEmail.focus();
        return false;
     }

}
0
Comment
Question by:bigbaboon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 7998389
From looking over your script, I'm assuming the problem is where you have stuff commented out, I'd try parseFloat() maybe:

function checkRange()
{
   temp = parseFloat(window.document.LeaseForm.txtLeaseAmount.value);

   if ( (temp<5000) || (temp>300000) )
   {
      alert("Lease Amount must be greater than $5000 and less than $300000.");
      window.document.LeaseForm.txtLeaseAmount.focus();
      window.document.LeaseForm.txtLeaseAmount.select();
   }
   else
   {
      //alert(temp);
      //Credit based Approval
      if( (temp >=5000) && (temp <= 100000) )
      {
         //window.document.LeaseForm.cmbApprovalProcess.value = "Credit Approval";
      }



      //Financials based Approval
      if( (temp > 100000) && (temp <= 300000) )
      {
         //window.document.LeaseForm.cmbApprovalProcess.value = "Financial Approval";
      }
   }
}

Also, instead of using document.LeaseForm everywhere you'll probably find it easier to pass the form object to the function parameter like this:

function validateForm(f)
{
   var errormsg = "";
   var focusfield;
   if ( f.strEmail.value == "" )
   {
      document.LeaseForm.strEmail.focus();
      errormsg += "You cannot leave email field empty.\n";
      if (!focusfield) focusfield = "strEmail";
   }
   if ( errormsg != "" )
   {
      alert( "Please correct the following errors:\n\n" + errormsg);
      if (focusfield) {
         eval( "f." + focusfield + ".focus()" );
         eval( "f." + focusfield + ".select()" );
      }
      return false;
   }
   else
   {
      return true;
   }
}

P.S. I don't know if this helps, but if you want only digits entered, I wrote a script for that; if nothing else, this will show you how to make your keycode checking more cross-browser:

function isNumericKey(e) {
   var k;
   document.all ? k = e.keyCode : k = e.which;
   return ((k > 47 && k < 58) || k == 8);
}
function extractNumeric(str) {
   return str.replace(/\D/g,"");
}

The reason for the second function, is even if you're checking the keycode and returning false on bad entries, users will still have the ability to paste characters you don't want in a field. Also, "auto-complete" overrides the keycode event as well... so I usually use the second function onchange or something to strip out any unwanted characters.

Does this help?

0
 

Author Comment

by:bigbaboon
ID: 8082959
Whammy,

sorry for the delay in responding but I have been away.

Would you be interested in completing this project for me?

Basically the calculator is asp and jscript based and needs tidying up to be completed. Some website work would also be required. I can let you know more if you are interested and you can let me know how much it would cost.

We can work out a payment method using either online system such as Paypal or more traditional means such as Western Union.

If you respond here with an email address (suggest using hotmail or yahoo initially to avoid spammers) I will be in touch shortly after.

Many thanks

0
 
LVL 4

Accepted Solution

by:
whammy earned 300 total points
ID: 8084492
rob k davis @ hot mail . com

Remove the spaces... :)
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9350157
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
LVL 3

Expert Comment

by:alexgreen
ID: 9679445

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Whammy's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

alexgreen
EE Cleanup Volunteer
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question