Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 5th, 2006, 11:00 AM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default Message Box (Show if form not filled out)

I have an asp page that consist of a user input form. On this form certain users are capable of filling in information and adding a new form (which will be added to the database that is linked to the webpage).

One of the fields for the form is a filename. The user will get this filename by pressing the "browse" button and searching for whatever file they want to include in their form. Well, if the user does not select a form when the press the "submit" button I receive an error message.

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: -1]'
/wwwroot/testecp/postNew1.asp, line 264


To prevent this from happening when the user is running on the actual page I wanted to make a message box appear when the user clicks the "submit" button and the notify him/her that they need to select a file name by selecting the browse button. Once the user presses ok on this message box I DO NOT want the submit to still process. I want it to stay on the page so the user can select a filename. I have the messagebox appearing when user clicks submit and a filename had not been selected, however, it is still sending the user to the next page (hence still generating the subscript out of range error").

This same error also occurs when the user attempts to type the filename in him/herself and does so incorrectly. I tried making the filename box "readonly" but then that also sets the button to read only so you cannot select the file. I also tried setting the file's textbox onClick event to show a messagebox whenever the user clicked the textbox to attempt to type in it, however, it sets the "browse" button for the file textbox to that also. So even if they don't attempt to type the filename themselves the messagebox still appears when they click the "browse" button to select the file.

Just trying to keep the users from gettin' any kind of error message at all. Any suggestions? (Code posted below)

[...code...]
<script language = "VBScript">
<!--
Option Explicit

function checkData()
dim myForm
set myForm = Document.forms("newEcpForm")
if myForm.ecpFilename.Value = "" then
msgbox("You must click the browse button and select a file.")
return true
else
myForm.submit
end if
end function

// -->
</script>

[...code...]


ECP Filename

</td>
<td width="550" colspan = "11">
<input type="file" name="ecpFilename" size="60" onClick="checkData()">

[...code...]

<td width = "50">
<input type="submit" name="submitButton" value="Submit" onClick="checkData()">
</td>
<td width = "50">
<input type="reset" name="resetButton" value="Reset">
</td>
<td width = "50">
<button>Cancel</button>

[...code...]





Toni Burgess
misskaos99@yahoo.com
__________________
T.B.
misskaos99@yahoo.com
Reply With Quote
  #2 (permalink)  
Old October 5th, 2006, 11:35 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I would actually use javascript for this (simply because I am more accustom to using it to validate client side and, to be 100% honest, have never used VBScript client side)

<script language=javascript>
<!--
  function checkData(){
     if (document.formname.ecpFilename.value.length == 0) {
          alert("Please select a Form to work with!\n");
      return false;
     }
  }

-->
</script>

in your form tag add something like this

<form name="myForm"> and the js line will become this:

document.myForm.ecpFilename.value.length == 0

*Remember* javascript is CASE SENSITIVE, so make sure you spell your form fields correctly!

hth.


--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply With Quote
  #3 (permalink)  
Old October 6th, 2006, 10:48 AM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

***I most definitely think VBScript is easier, but I'm learning....

AnyWHO, it's not working.  I've been at it for a couple of hours this morning and it's still doing the same thing.  (No message box appears when I hit the submit button, just goes on to the "Page cannot be displayed"  And it gives me this error:
Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: -1]'
/wwwroot/testecp/postNew1.asp, line 271


Which is due to me not selecting a filename.

It shows a little error caution sign at the bottom left hand corner of the screen (when I press the back button).  It says I have a syntax error on Line 19, Char 2, Code 0 (no clue what that means-- the code 0 part) on the PostNew1.asp page.  This only occurs when I press the back button.  

Now this is what I have....

PostNew1.asp

<%
if Session("UserID") = "" then
  Response.Redirect("index1.asp")
end if
%>

<%
if Session("UserType") <> "originator" then
  Response.Redirect("noPostNew1.asp")
end if
%>

<html>
<head>


<title>Post New ECP/IMI Impact Form</title>

<script language="javascript">
<!--

  function checkData(){
     if (document.myForm.ecpFilename.value.length !== 0 ) {
          alert("Sending data...");
     form.submit
      return true;
     }
    }
 else {
    alert("missing file");
   return false;
   end if
  }
  }
 end function
-->
</script>

</head>

[...code...]
'start of form--so u can see how it's name, etc.
<form name="myForm" method="post" action="postNew1.asp" enctype="multipart/form-data">

[...code...]

'The following is where the filename is located at on the form


ECP Filename

</td>
<td width="550" colspan = "11">
<input type="file" name="ecpFilename" size="60">
<br>

(Please ensure the adobe filename&nbsp;


does not have spaces.


You may use underscores.)


[...code...]

'I posted the following code also because this is the reason for me getting the error when I do not select a filename...  Thought maybe I need to be adding my script down there somewhere instead. ?

<%

set o = new clsUpload
if o.Exists("submitButton") then

  'get client file name without path
  sFileSplit = split(o.FileNameOf("ecpFilename"), "\")
  sFile = sFileSplit(Ubound(sFileSplit))

  'Upload filename
  o.FileInputName = "ecpFilename"
  o.FileFullPath = Server.MapPath(".") & "\ecpFiles\" & sFile
  o.save

  'If not error redirect to complete message
  if o.Error = "" then

    Dim pSQLStatement, pConnection
    Dim pRS, objMail
    Dim pEcpNumber, pEcpTitle, pEcpFilename, pEcpOriginator, pEcpDateDistributed, pEcpDateDue

    pEcpNumber = o.ValueOf("ecpNumber")
    pEcpTitle = o.ValueOf("ecpTitle")
    pEcpFilename = sFile
    pEcpOriginator = o.ValueOf("ecpOriginator")
    pEcpOriginator = Session("UserFullName")
    pEcpDateDistributed = CStr(date())
    pEcpDateDue = CStr(o.ValueOf("ecpDateDue"))


pConnection = "Provider=SQLOLEDB.1;UID=sa;PWD=;Initial Catalog=ecpDatabase2SQL;Data Source=localhost"
Set pRS = server.CreateObject("ADODB.RecordSet")

   pRS.open "INSERT INTO ecpForms (ecpNumber, ecpTitle, ecpFilename, ecpOriginator, ecpDateDistributed, ecpDateDue) VALUES ('" & pEcpNumber & "', '" & pEcpTitle & "', '" & pEcpFilename & "', '" & pEcpOriginator & "', '" & pEcpDateDistributed & "', '" & pEcpDateDue & "') ", pConnection

[...code...]

Thanks for all your help  
misskaos99

Quote:
quote:Originally posted by dparsons
 I would actually use javascript for this (simply because I am more accustom to using it to validate client side and, to be 100% honest, have never used VBScript client side)

<script language=javascript>
<!--
  function checkData(){
     if (document.formname.ecpFilename.value.length == 0) {
          alert("Please select a Form to work with!\n");
      return false;
     }
  }

-->
</script>

in your form tag add something like this

<form name="myForm"> and the js line will become this:

document.myForm.ecpFilename.value.length == 0

*Remember* javascript is CASE SENSITIVE, so make sure you spell your form fields correctly!

hth.


--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Toni Burgess
misskaos99@yahoo.com
Reply With Quote
  #4 (permalink)  
Old October 6th, 2006, 11:02 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Oh wow, you totally destroyed that javascript code! O.o Its ok though. (Sorry I am a C# guy, I like javascript more ;] ) ANYWAY!

I took the liberty of editing your javascript and I threw together a quick HTML page so Ill explain it to you:


<script language="javascript">
<!--

  function checkData(){
     if (document.myForm.ecpFilename.value.length == 0 ) {
      alert("missing file");
      return false;
     }
    else {
          alert("Sending data...");
      myForm.submit();
          return true;
    }
  }
-->
</script>

First off, Javascript doesnt have "End Sub, Function, If" it uses { } to determine the begining and end of a code block.

Now, when you rewrote the javascript you had the logic backwards, becauces you were submitting the form when the file field was empty and not submiting the form when the file field had something in it.

The VBScript equiv to the above javascript is:
Dim s
s = Request.Form("ecpFilename")
If s = "" then
//alert message
else
//post form
end if

Also, you had: form.submit, this is a syntax error it needs to be:
myForm.submit();

Here is the HTML that i used:

<body>
<form id="Form1" method="post" name="myForm">
<P><INPUT type="file" name="ecpFilename"></P>
<P><INPUT type="button" onclick="checkData()" value="Button"></P>
</form>
</body>

hth

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply With Quote
  #5 (permalink)  
Old October 6th, 2006, 11:07 AM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

lol I have no idea how it got changed so much. Trying to fix 2-3 things at once. lol Sorry. Okay, I'm going to go print the post out and try that (with javascript, mostly everywhere I searched does it in Javascript, so i'm going to try that first). Thanks a bunch ;)

Quote:
quote:Originally posted by dparsons
 Oh wow, you totally destroyed that javascript code! O.o Its ok though. (Sorry I am a C# guy, I like javascript more ;] ) ANYWAY!  

I took the liberty of editing your javascript and I threw together a quick HTML page so Ill explain it to you:


<script language="javascript">
<!--

  function checkData(){
     if (document.myForm.ecpFilename.value.length == 0 ) {
      alert("missing file");
      return false;
     }
    else {
          alert("Sending data...");
      myForm.submit();
          return true;
    }
  }
-->
</script>

First off, Javascript doesnt have "End Sub, Function, If" it uses { } to determine the begining and end of a code block.

Now, when you rewrote the javascript you had the logic backwards, becauces you were submitting the form when the file field was empty and not submiting the form when the file field had something in it.

The VBScript equiv to the above javascript is:
Dim s
s = Request.Form("ecpFilename")
If s = "" then
//alert message
else
//post form
end if

Also, you had: form.submit, this is a syntax error it needs to be:
myForm.submit();

Here is the HTML that i used:

<body>
<form id="Form1" method="post" name="myForm">
<P><INPUT type="file" name="ecpFilename"></P>
<P><INPUT type="button" onclick="checkData()" value="Button"></P>
</form>
</body>

hth

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Toni Burgess
misskaos99@yahoo.com
Reply With Quote
  #6 (permalink)  
Old October 6th, 2006, 11:14 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Good luck! Ill be around if you need anymore help....

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply With Quote
  #7 (permalink)  
Old October 6th, 2006, 11:36 AM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

*PULLING HAIR OUT WHILE CURSING THE COMPUTER MONITOR*

Okay, I think I've calmed down now. This thing wants to drive me crazy today, but I've gotten it out of my system. Now, it is still doing the same thing, no msgbox, little caution sign, etc.

Maybe there's a more efficient and simpler way to do this. The way I see it, the message box isn't going to do me any good anyway because as long as it's not empty the program will work (with the javascript msgbox working). But it shouldn't allow the user to enter a filename at all. What would u suggest be the easiest way to make this happen?

I was thinking of throwing the whole msgbox thing out all together (I'll figure out how to work with that on another program) and maybe making the submit button readonly until the user selects a filename. I don't know, what do u think?

It's not required, but it just seems silly that they wouldn't have some sort of validation check to make sure the user selects a file, rather than typing one or leaving it blank. If they do either (type it in--it's very rare they'll get the entire file path right-- or leave blank), once they select the submit they're going to get that "Page cannot be displayed" page. They're not going to understand the "error message" so it seems only logical to add something to prevent this from occuring. It's almost like a crooked picture in a doctors office, it's just going to drive me crazy.

Please advise.

Toni Burgess
misskaos99@yahoo.com
Reply With Quote
  #8 (permalink)  
Old October 6th, 2006, 11:43 AM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

just a quickie...

see like right here
  'Upload filename
  o.FileInputName = "ecpFilename"
  o.FileFullPath = Server.MapPath(".") & "\ecpFiles\" & sFile 'line270
  o.save

Like here, maybe I need to be putting a validation check somewhere in here. if ecpFilename = "" then display a msgbox and return false? else it would continue on with o.FileFullPath = etc etc

Toni Burgess
misskaos99@yahoo.com
Reply With Quote
  #9 (permalink)  
Old October 6th, 2006, 11:57 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I like quickies.

Ok, take a deep breath, sit back and relax. Yes you are right, if i typed even the letter A into the file upload box, the javascript would allow me to pass and bomb your script; welcome to the fun world of error handling!

A word of warning before I continue on, using errors to control program flow is generally a bad idea (at the very least poor practice) unfortunately, sometimes it is the only way. =\ (Just dont make it a habit)

There is a bunch of things that you can do before an error can be thrown, examine the string, does if contain \ / or :? if it doesnt you know its not a valid path and that you should exit execution. Also I would leave the javascript in there as another measure of validation.

Lastly, on to the error checking. I am not going to actually write this out, 4Guys did a really great job of it and you can read the article here:

http://www.4guysfromrolla.com/webtech/060399-1.shtml

What you can examine is the type of error, Err.Description = "File not found" or something like that then you know that the user supplied an invalid file, exit program execution and warn them about it.

hth

p.s. check your yahoo mail before you leave work.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply With Quote
  #10 (permalink)  
Old October 6th, 2006, 12:42 PM
Authorized User
 
Join Date: Sep 2006
Location: Jax, NC, USA.
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

*BTW: Everyone likes quickies...:D *

Still maintaining my sanity....

Not working still.  No msgbox, my error handler isn't logging errors (or actually I think it is, I just don't have them coming out right--but that's the least of my worries right).  I don't know what it is but this little caution box is irritating me and has led me to believe if I don't fix that, it's just not going to work.

soo once again here is the error message I continuously keep receiving once I refresh, go back, push submit, etc.

error msg:

Line: 11
 Char: 2
Error: Syntax Error
Code: 0
URL: http://localhost/wwwroot/testecp/postNew1.asp


<%
if Session("UserID") = "" then
  Response.Redirect("index1.asp")
end if
%>

<%
if (Session("UserType") <> "originator") then
 Response.Redirect("noPostNew1.asp")
end if
%>

<% On Error Resume Next %>


<script language="javascript">
<!--
  function checkData(){
     if (document.myForm.ecpFilename.value = "" ) {
          alert("missing file");
      return false;
     }
  }
 else {
    alert("sending data...");
   myForm.submit();
   return true;
    }
 }
 
-->
</script>
<%
if Err.number <> 0 then
  TrapError Err.description
End if
%>


Toni Burgess
misskaos99@yahoo.com
Reply With Quote
Reply


Thread Tools
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
IBM AS400 Message Errors to show them in .NET appl julenis SQL Server 2000 2 July 12th, 2006 02:45 PM
IBM AS400 Message Errors to show them in .NET appl julenis C# 0 July 12th, 2006 11:28 AM
DTS, SQL Server, Show PK value in err message zpluug .NET Framework 2.0 7 March 10th, 2006 12:50 AM
how to show a confirmation message? noor ASP.NET 1.0 and 1.1 Basics 10 May 16th, 2005 04:12 AM
I cannot disabled show windows message “internet e woland666 Visual C++ 0 June 28th, 2004 06:35 AM



All times are GMT -4. The time now is 03:02 AM.


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