Solved

Javascript form check with variable from database

Posted on 2003-10-27
4
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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