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

Javascript form check with variable from database

How can i check an input of a textbox and make sure its not greater than a variable that is set in my database.

My need is to ask a user how long it took them to read through a lesson and take some questions on the content they just read.  In the database there is a variable that will act as the Max number of credits they are allowed to recieve.  So for instance for one lesson, the max credits they can recieve is '2'.  Then in the form where it will ask how long it took them.  So for any answer over 2, I would like an alert box to pop up and say that it is over the maximum allowed credits when they hit the submit button.  Is this possilbe.

Thanks,
Jeff
0
jeffmace
Asked:
jeffmace
  • 2
  • 2
1 Solution
 
CFDevHeadCommented:
here is quick and dirty script
<cfset  myVariable=2>
<cfoutput>
<script>
function chkCredits(f){
      var maxCredits = #myVariable#;
      if (f.credits.value > maxCredits){
            alert('That it is over the maximum allowed credits.')
            return false;
      }else{
            return true;
      }
}
</script>
</cfoutput>
<form action="index.cfm" onsubmit="return chkCredits(this)">

<input type="text" name="credits">

<input type="submit">

</form>

good luck
0
 
jeffmaceAuthor Commented:
For some reason it doesn't seem to be working.  It's just going to the requested page even though i am entering in a 6 when the max value can be a 1
0
 
CFDevHeadCommented:
Here is a working example: http://sylvansupply.com/test.cfm
0
 
jeffmaceAuthor Commented:
My fault, I forgot I had <CFFORM> in there.  Maybe you can help me with the other questions I just posted regarding Javascripts and forms.
0

Featured Post

Get your problem seen by more experts

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

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