Solved

Javascript form check with variable from database

Posted on 2003-10-27
4
174 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 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