Solved

Javascript form check with variable from database

Posted on 2003-10-27
4
172 Views
Last Modified: 2013-12-24
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
Comment
Question by:jeffmace
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 500 total points
Comment Utility
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
 

Author Comment

by:jeffmace
Comment Utility
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
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
Here is a working example: http://sylvansupply.com/test.cfm
0
 

Author Comment

by:jeffmace
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now