Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate and change entered text

Status
Not open for further replies.

RottPaws

Programmer
Mar 1, 2002
478
US
I'm trying to migrate a VB app I have to the web.

I'm using InterDev to build .asp pages.

I've created a form that accepts a customer account number and then retrieves information about that account when a button is clicked.

It works great except that the database I'm querying uses a 9-character text field for the account number. So if the account number the user is looking up only has 7 digits, it needs 2 leading zeros.

In VB, I have have a validation procedure in the Lost_Focus event that checks the length of the entered text and if len(Cust_No) < 9, it adds a '0' to the front of the account number and then loops until len(Cust_No)=9.

How do I do the same thing in my web page?

Thanks in advance. _________
Rott Paws
 
in html you could use the onBlur event for an input tag.
<input type=text onblur='myValidateField()'>

<script language=vbscript>
sub myValidateField()
your code here
end sub
 
<input type=submit onclick='myValidateField()'>


<script language=&quot;javascript&quot;>
function myValidateField(){
le=document.form_name.accno.length
if le<9 then{
***enter code for 0 stuffing
}
}

 
I'm having trouble getting either of the above suggestions to work.

Where do I put the <script . . . .> and the function/sub?
Once I get it in the right place, it also needs a </Script>, right? _________
Rott Paws
 
i would put the script before your </body> tag.

and yes you do need a </script> tag.
 
I'm sort of making progress. I now have it getting to the sub using the vbscript suggestion, but I get an error there.

I've got a line of code that says
do while len(Cust_No)<9 then
but it says this is an invalid reference.

What is the syntax to reference the field in the form?

_________
Rott Paws
 
try
document.[myform].[myfield].value
in place of Cust_No

where [myform] is your form name
and [myfield] is the field you need to validate

 
Excellent!!! Works great!

Thanks a bunch!!! _________
Rott Paws
 
My form name is GetCriteria and it has a field called Cust_No.

The HTML for the field is:
<INPUT type=text onblur='CustNoValidate()' id=Cust_No maxLength=9 name=Cust_No value=&quot;<%=Cust_No%>&quot;>

The procedure to insert leading zeros to the account number is below.

<script language=vbscript>
sub CustNoValidate()

do while len(document.GetCriteria.cust_No.value)<9
document.GetCriteria.cust_No.value=&quot;0&quot; + document.GetCriteria.cust_No.value
loop

end sub

</script> _________
Rott Paws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top