[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript  validation error

Posted on 2012-09-10
5
Medium Priority
?
324 Views
Last Modified: 2012-09-11
Could someone take a look at this and tell me where the error is?


<html>
<head>
<script type="text/javascript">
function Valdt() {
  var ErrMsg = "";
  var sTo = document.forms[0].iTo.value;
  var sFrom = document.forms[0].iFrom.value;
  var iDiff=0;
  if (sTo == "") {
    ErrMsg = "Please enter To record number. \n";
  }
  if (sFrom == "") {
    ErrMsg = "Please enter From record number. \n";
  }
// I know it's good up to here, but I just don't see any error past this.
  if (Errmsg == "") {
     var iTo =  parseInt(sTo,10);
     var iFrom = parseInt(sFrom,10);
     iDiff = (iTo-iFrom);
     if (iDiff > 301)  {
        ErrMsg = "Please enter 300 or less records to process. \n";
     }
  }
  if (ErrMsg == "") {
    document.forms[0].action='email1.asp';
    document.forms[0].submit();
   }
   else  {
    document.forms[0].action='email.asp';
    document.forms[0].submit();
  }
}
</script>
</head>
<body>
<form method=post>
From Record:
     <input name="iFrom" size="9" value="0">
<BR>
 To record:
     <input type="text" name="iTo" size="9" value="300">
 <INPUT TYPE="submit" border=1  VALUE="Submit" onClick="Valdt()">
</form>
</body>
</html>
0
Comment
Question by:dcass
5 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 1200 total points
ID: 38385379
hi, its typo..
in the below line (from your code) "m" is in samll, it should be capital 'M'
if (Errmsg == "") {

change it to

if (ErrMsg == "") {
0
 
LVL 12

Assisted Solution

by:Amick
Amick earned 800 total points
ID: 38385396
Errmsg is used rather than ErrMsg in the line following
// I know it's good up to here, but I just don't see any error past this.

Because case matters, Errmsg is undefined at that point.

You may also want to use the  exactly equal  operator "===" where appropriate.
0
 
LVL 12

Expert Comment

by:Amick
ID: 38385408
Although there was no answer when I started my response, ansudhindra was quicker with a reply and should be rewarded appropriately.
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 38385447
Java-Script is case sensitive language.

You have written wrong variable name:

if (Errmsg == "") {

This should be:

if (ErrMsg == "") {
0
 

Author Comment

by:dcass
ID: 38386805
I was just too tired to see it!
Thanks for your quick response.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 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