Link to home
Start Free TrialLog in
Avatar of bigbaboon
bigbaboonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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;
     }

}
Avatar of whammy
whammy

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?

Avatar of bigbaboon

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of whammy
whammy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:
https://www.experts-exchange.com/help/closing.jsp


Cd&


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