Solved

How can I submit a form depend on the input?

Posted on 1998-10-08
6
160 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

18 Experts available now in Live!

Get 1:1 Help Now