Solved

How can I submit a form depend on the input?

Posted on 1998-10-08
6
163 Views
Last Modified: 2013-12-25
There is an input box in my asp, like this" <form name="frmSave1" method="POST" action="/cargo/save.asp">
<p><input type="text" name="T1" size="5"> ...."
if T1 is A~Z ,submit the form,else don't submit it.
How can I do this?Thank you very much!!
0
Comment
Question by:lijin1
  • 4
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1828973
<SCRIPT LANGUAGE="JavaScript"><!--

// --------------------------------------------------------------------
// COMPANY:       Netscape Communications
// AUTHOR:        Robert W. Husted
// DATE CREATED:  March 17, 1997
// MODIFIED BY:
// DATE MODIFIED:
// --------------------------------------------------------------------

// CHECK STRING - ENSURE ALL CHARACTERS ARE LETTERS
function toAlpha(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING

    // LOOP THROUGH STRING CHARACTER BY CHARACTER
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS AN ALPHA CHARACTER
        if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" )) {
            newString += ch;
        }
    }

    if (checkString != newString) {
      // VERIFY WITH USER THAT IT IS OKAY TO REMOVE INVALID CHARACTERS
      if (confirm("The value you have entered\ncontains invalid characters,\nis it okay to remove them?")) {
        // RETURN REVISED STRING
        return newString;
      } else {
        // RETURN ORIGINAL STRING
        return checkString;
      }
    }
    return checkString;
}

/* This is added by me */
function checkSubmit(theForm) {
   Text = theForm.T1.value;
   ChkText = toAlpha(Text);
   if ( Text == ChkText ) return true;
   else {
      theForm.T1.value = ChkText;
      retun false;
   }
}
//--></SCRIPT>
<form name="frmSave1" method="POST" action="/cargo/save.asp" onSubmit="return checkSubmit(this)">
<p><input type="text" name="T1" size="5">
</FORM>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1828974
Oops, typo - retun should be return:

   else {
        theForm.T1.value = ChkText;
        retun false;
   }

should be

  else {
          theForm.T1.value = ChkText;
          return false;
   }
0
 

Author Comment

by:lijin1
ID: 1828975
Thank you very much, mplungjan.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 10

Expert Comment

by:MasseyM
ID: 1828976
Why was this rejected?  
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1828977
Thanks MasseyM, I was wondering the same thing, perhaps the wrong radio was selected?

Michel
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 200 total points
ID: 1828978
I will reanswer this in case Lijin1 just went away, not to come back...

Michel
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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

910 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

21 Experts available now in Live!

Get 1:1 Help Now