Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 4th, 2008, 03:11 AM
Registered User
Join Date: Sep 2008
Location: Springs, Gauteng, South Africa.
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>

Reply With Quote
  #2 (permalink)  
Old September 4th, 2008, 01:09 PM
Friend of Wrox
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

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:

' 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, "" );
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 03:30 PM.

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