JavaScript script to parse text fields from multipart/form-data

N

nate

Hello,

Does anyone know where I can find an ASP server side script written in
JavaScript to parse text fields from a form method='POST' using
enctype='multipart/form-data'? I'd also like it to parse the filename.

<form name='form1' method='POST' enctype='multipart/form-data'
action='sub.asp'>
<input type='text' name='title1' value='value1'>
<input type='file' name='file1'>
</form>

I found a great ASP VBScript for uploading files, but the rest of my
Web site is coded in ASP using JavaScript and I can't figure out a way
to immediately pass the text fields already parsed from server side
VBScript to server side JavaScript.

My ASP code looks like this:

<script language="JavaScript" runat="server">
//I would like to add JavaScript to parse the text field and
filename of file1 here.
</script>
<!--The 3rd party document below parses all fields from the message
content and uploads any file fields it encounters.--->
<!--#include file="aspinclude/upload.asp"-->
<script language="JavaScript" runat="server">
//Add record here (title1, filename from file1).
</script>

Thanks For Your Help,

Nate
 
J

Jeff North

On 5 Oct 2004 14:32:46 -0700, in comp.lang.javascript
| Hello,
|
| Does anyone know where I can find an ASP server side script written in
| JavaScript to parse text fields from a form method='POST' using
| enctype='multipart/form-data'? I'd also like it to parse the filename.
|
| <form name='form1' method='POST' enctype='multipart/form-data'
| action='sub.asp'>
| <input type='text' name='title1' value='value1'>
| <input type='file' name='file1'>
| </form>
|
| I found a great ASP VBScript for uploading files, but the rest of my
| Web site is coded in ASP using JavaScript and I can't figure out a way
| to immediately pass the text fields already parsed from server side
| VBScript to server side JavaScript.

You might try using a session variable.
 
N

nate

Jeff,

Thanks for your reply.

I already tried using Session and Application variables. This doesn't
work because the Session (and Application) variables are not updated
by the time the second <script language="JavaScript" runat="server">
gets executed. The ASP engine seems to run each code block in one page
asynchronously:
E.G.

1) <script language="JavaScript" runat="server">
1) <!--#include...--->
1) <script language="JavaScript" runat="server">

....not...

1) <step>
2) <step>
3) <step>

The Session (and Application) variables are only updated WHEN I
refresh the page.

I never solved this dilema, but I did come up with a work-around. I
just coded the whole page in VBScript (a pain-in-the-butt for me since
I mostly use JavaScript) and everything is working now. It seems silly
to me that you can do so much using JavaScript, and then suddenly hit
a road block (e.g. I can't upload a file to the server using
JavaScript). Maybe the next guy will read this and not spend 5 hours
trying to get the code to work using JavaScript?

Thanks,

Nate
 
J

Jeff North

On 6 Oct 2004 12:11:29 -0700, in comp.lang.javascript
| Jeff,
|
| Thanks for your reply.
|
| I already tried using Session and Application variables. This doesn't
| work because the Session (and Application) variables are not updated
| by the time the second <script language="JavaScript" runat="server">
| gets executed. The ASP engine seems to run each code block in one page
| asynchronously:
| E.G.
|
| 1) <script language="JavaScript" runat="server">
| 1) <!--#include...--->
| 1) <script language="JavaScript" runat="server">
|
| ...not...
|
| 1) <step>
| 2) <step>
| 3) <step>
|
| The Session (and Application) variables are only updated WHEN I
| refresh the page.
|
| I never solved this dilema, but I did come up with a work-around. I
| just coded the whole page in VBScript (a pain-in-the-butt for me since
| I mostly use JavaScript) and everything is working now. It seems silly
| to me that you can do so much using JavaScript, and then suddenly hit
| a road block (e.g. I can't upload a file to the server using
| JavaScript). Maybe the next guy will read this and not spend 5 hours
| trying to get the code to work using JavaScript?

I feel your pain as I had the same problem not so long ago.
I use Lewis Moten's Upload without com scripts (writtin in VBScript)
but my pages are written in JScript.

The way I worked around this was to (I coded this for the company's
intranet so I know the set up was ok).
a. call the popup window that selects the file - no changes here
b. the second window that performs the actual upload I changed to use
a cookie to set the filename + the getElementById to so the name of
the parent page.
 
J

J. J. Cale

Regarding the use of file upload modules. As I understand it asp files will
only run on Windows Servers. Server side javascript (which I've never used)
would seem to be more portable. Or php which runs basically cross platform.
Is the OP relating to a Win environment? Where can I get a file upload
module written in VB that will work without a dll? BTW I tried the link to
Lewis Motens page but my browser (IE5) throws an error (XML something or
other) and I can't get to the download page. TIA
Jimbo
 
N

nate

J.J.,

The 'module' I used is located at:
http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7093&lngWId=4
.. It works great. Don't forget to use the faster version (you'll see
after you download the files). The script uploads your file and parses
all form fields. Make sure you have write permissions in the directory
you run the scripts. Tweaking the code to my specifications was easy
(it took about an hour and I don't code ASP pages in VBScript much -
mostly in JavaScript).

P.S. I inserted a few additional comments below.

Good Luck!

Nate...

J. J. Cale said:
Regarding the use of file upload modules. As I understand it asp files will
only run on Windows Servers.

The only way I've ever used ASP (Active Server Page) scripts is with
Windows 2000 - IIS (Internet Information Services). I think you can
also use ASP scripts with whatever dynamic web server optionally came
with Windows NT 4?
Server side javascript (which I've never used) would seem to be more
portable. Or php which runs basically cross platform.

I'm not sure what you mean by 'more protable'? Client-side and
Server-side VBScript and JavaScript scripts can easily be copied and
pasted into your .asp, .htm, and .html files, but you could not do
something like say, copy Server-side ASP scripts into your PHP (CGI)
dynamic Web server.
Is the OP relating to a Win environment?

As you will see when you download the script files, the 'OP'
(operation?) for the upload-part of the code uses the FileSystemObject
to upload a file to a Windows environment. I'm not sure if you can
specify a location other than a Windows local path, such as a Unix
path or a network share? Google the FileSystemObject or look on MSDN's
Web site for the documentation on this object.
 
M

MikeT

Jeff,

Thanks for your reply.

I already tried using Session and Application variables. This doesn't
work because the Session (and Application) variables are not updated
by the time the second <script language="JavaScript" runat="server">
gets executed. The ASP engine seems to run each code block in one page
asynchronously:
E.G.

1) <script language="JavaScript" runat="server">
1) <!--#include...--->
1) <script language="JavaScript" runat="server">

...not...

1) <step>
2) <step>
3) <step>

Your problem is mixing languages in one ASP page - the execution order
is not obvious or the order the scripts appear in the file. It's one
of the petty niggles of ASP - see
http://www.aspfaq.com/show.asp?id=2045

Once you understand how the ASP engine works, mixing languages is not
a problem. I've got one page that (for various reasons) has VBscript,
JScript and Perl all running together and once I'd read that article,
all was well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top