• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

how to restrict form selections based on user entry validations

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
bigbaboon
Asked:
bigbaboon
1 Solution
 
whammyCommented:
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
 
bigbaboonAuthor Commented:
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
 
whammyCommented:
rob k davis @ hot mail . com

Remove the spaces... :)
0
 
COBOLdinosaurCommented:
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
 
alexgreenCommented:

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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now