Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2008, 03:11 AM
Registered User
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Message box

Hi you all please help me. I'm stuck on a txt_onblur problem. Here is code:

sub txtname_onblur()
    document.body.all("txtName").value = replace(document.body.all("txtName").value,"'","")
    document.body.all("txtName").value = replace(document.body.all("txtName").value,"/","")
    document.body.all("txtName").value = replace(document.body.all("txtName").value,"!","")
    document.body.all("txtName").value = replace(document.body.all("txtName").value,"?","")
end sub

Ok so the problem is that I have to in put this code into all my pages that has a message box, [u]WHERE DO I DO THAT? PLEASE HELP</u>


 
Old September 4th, 2008, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You should be able to put this into a ".inc" file and then just do

at the top of each page.

If a page doesn't happen to have a txtName field, I don't think it will hurt. The sub just won't do anything, then.

I hope you are aware that this means that your pages will *ONLY* run with MSIE browsers, as only MSIE allows VBScript in the browser.

If this is the only VBScript you are using in your pages, you'd be much better advised to convert it to JavaScript, so that it would work in all browsers.

Finally, you can simplify the heck out of that code thusly:

Code:
' do this outside the SUB for efficiency:
Dim reZap
reZap = New RegExp
reZap.Pattern = "[\'\/\!\?]"
reZap.Global = True

Sub txtname_onblur()
    Dim fld = document.body.all("txtName")
    fld.value = reZap.Replace( fld.value, "" )
End Sub
This also makes it easy to add other zappable characters to the list, just by adding them into the .Pattern value.

Alternatively, you could specify only the characters you want to *KEEP* by doing something like:
reZap.Pattern = "[^a-zA-Z0-9\,\s\-]"
which will say "zap all characters *EXCEPT* those I list". (The leading ^ character inverts the sense of the match.)

Lastly, should you decide to change to JavaScript, that's easily done, as well:

<script language=JavaScript>
function txtname_onblur( )
{
    var fld = document.forms[0].txtName;
    fld.value = fld.value.replace( /[\'\/\!\?]/g, "" );
}
</script>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Message box in C# shikha09 C# 0 November 28th, 2006 01:24 AM
how to use message box? andy hee ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2006 04:53 AM
message box nalla ASP.NET 2.0 Professional 4 December 23rd, 2005 03:00 AM
Yes No Message box dbartelt Access 7 October 28th, 2005 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.