Solved

Javascript form check with variable from database

Posted on 2003-10-27
4
173 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
ID: 9629085
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
ID: 9629528
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
ID: 9629548
Here is a working example: http://sylvansupply.com/test.cfm
0
 

Author Comment

by:jeffmace
ID: 9629682
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

24 Experts available now in Live!

Get 1:1 Help Now