Solved

How can I submit a form depend on the input?

Posted on 1998-10-08
6
170 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

791 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