Can you create/Edit files using JavaScript?


Results 1 to 13 of 13

Thread: Can you create/Edit files using JavaScript?

  1. #1
    Lucefiel Guest

    Can you create/Edit files using JavaScript?

    This post is related to my OK, here goes... post.

    Is there any way in JavaScript to create a file and input values into it? Or, since <IRK>Windows</IRK> creates .TMP files to store information "posted" from a JavaScript form, is there any way to open a file, modify the contents of the file (i.e. make it easier to read) and save the changes?

    Or, better yet, is there a way to insert information into the body of an E-Mail using JavaScript (from a JavaScript Form)?

    If any of these questions don't seem to make any sense, please read the post referenced above for more information.

    EDIT
    ------------------

    To make things simpler, I've taken all the information from the other posts and put them into this one...

    the URL of my form is: http://www.cs.hesston.edu/MichaelN/TestJSForm/Form.html

    Description: I'm trying to create a JavaScript E-Mail form that will allow people to subscribe to a free Newsletter. I would like it if the information entered in the form could be somehow put into the body of the E-Mail being sent, but right now the information is being sent in the form of a temporary file that is being sent as an attachment.

    The Problems: First off, the way the information is being sent (as an attachment) is not the way I would prefer to do it, but if I can get the info to be formatted the way I want, I'll be able to live with it (for now). The main problem is that the information is being send in this format:

    LastName=Last Name&FirstName=First Name&Company=Company Name&StreetAddress=Street Address Number+Street Name+Street Type (dr., st., etc.)&City=City&State=State Abbr&ZIP=Zip Code&Email=E=Mail Address

    The Fix: What I would really like to do is put the information into the body of the E-Mail in the following format:

    Name: Last Name, First Name
    Company: Company Name
    Address: Street Address
    City: City
    State: State Abbr
    ZIP Code: ZIP
    E-Mail Address: E-Mail Address

    But I don't know how to do this...

    ------------------
    May the best of your past be the worst of your future.

    [This message has been edited by Lucefiel (edited 06 October 2000).]

  2. #2
    stiles Guest
    Originally posted by Lucefiel:
    Can you create/Edit files using JavaScript?
    I really hope you can't!!!! A few lines of JS code could wipe out your harddrive if that was possible. JS is not designed to do that.

    What are you trying to do with your form? Do you have to do it by email or can you use a server side script? You may be able to use a cookie for temp data stroage.

  3. #3
    Lucefiel Guest
    Eventually I would like to go to Server Side, but I can't get that to work at all so I'm trying to set this up as a stopgap.

    Can I modify cookies using JavaScript? How?

    Also the formatting (mentioned in my first post, "OK, here it is...") is another major part of my problem too. I'm designing this form for someone else that doesn't have a lot of extra time on his hands (and isn't too good with computers) so it has to be easily readable.

    While I can write a program to take the TMP files and reformat them the way I want, I don't want to have to do that because, with the amount of submissions that will (hopefully) be sent in, it will be too time consuming to filter all the files through another program.

    ------------------
    May the best of your past be the worst of your future.

  4. #4
    per©oDåN Guest
    YOu can declare variables create arrays for temp storage (during a client's session only, however)... I guess I'll have to read your other post/lookit your page to figure out exactly what you're axing...

    brb (if that applies to a bbs...?)

    -perc

  5. #5
    Lucefiel Guest
    I've updated my original post so you don't have to jump around as much to figure out what's going on. The updated information is after EDIT.

    ------------------
    May the best of your past be the worst of your future.

  6. #6
    per©oDåN Guest
    Originally posted by Lucefiel:
    Eventually I would like to go to Server Side, but I can't get that to work at all so I'm trying to set this up as a stopgap.
    You need to... for the reasons below (that you have said you require). What cgi apps have you tried? (didja write your own?)


    Also the formatting ... is another major part of my problem too ... so it has to be easily readable.
    Although there are a few things you can do programmatically within the form using JavaScript, like ensuring format/integrity of input, for a form to do anything more than send a straight text dump of the form data (including control characters) to an e-mail address, the form data will need to be passed to some kind of CGI script, or exe running on an available server for processing
    there, then sending. (It would seem you already know this, however, I mention it j-i-c)


    While I can write a program to ... it will be too time consuming to filter all the files through another program.
    No, it prolly won't... unless the server is like a 386 with 4 megs of RAM, and even then, it wouldn't be too excruciating... There are lots of FREE, well-written cgi's out there... get one if you have access to a server to install it on.

    If I had the time, I'd let you use one of mine, but you'd learn how mine works and not the one you might use in the future, (although they're mostly all similar).

    Even a VB EXE will do this stuff for you...

    It's the best [only] way to go, really.

    Some things to think about:

    * What if your clients are connecting from shared systems where they don't have a dedicated e-mail client installed or configured?

    * Many people will choose not to use that method, as it does not allow for anonymous submissions.

    * With cgi apps, you can sometimes take advantage of special cgi environment variables to obtain details about the client submission like IP address and other schtuff...

    -perc

    BTW: your HTML (that is actually the functional part of a form, not the JS) seems to be in good order... however if you expect the amount of traffic you alluded to above, you *might* want to add 'maxlength' attributes to your text input fields...

    (wouldn't want someone flooding your e-mail box one night, would you?)

    If you want to have JavaScript validate information on the form before submitting, THAT is very possible and entirely easy...

    It looks like you got your source from some example in a book...right?

    Read the book it came with... validation ain't hard.

  7. #7
    per©oDåN Guest
    In case you get really aggrivate by people saying "Use server-side cgi", I'll also mention this:

    You can also create functions in JS that [before the data is submitted] declare variables and add/insert form data to them to produce a semi-formatted character stream that could have HTML tags included [transparently to the user or e-mail recipient] that could be read by an HTML-capable e-mail client at 'formatted' data.

    This would be much more of a pain-in-the-*** than finding a free server out there or getting a free script, though...

  8. #8
    david Guest
    The solution(or at least part of it):
    Go to http://www.f2s.com
    It's a free host, with PHP and MySQL. It runs Debian on kernel 2.4, and the servers are pretty fast, and I'm on crappy dial up.

    Then, go to: http://php.thescripts.com
    There are tutorials on how to make a mailto PHP script, which is REALLY simple, compared to Perl.

    ------------------
    David V.
    PEI, Canada (The Potato on a Stick)
    Drake user since June 2000
    LNO Linux
    -----------------
    Microsoft announcement: "Microsoft has decided to license the popular Windows(tm) OS under the GNU GPL"
    Child to mother: "Look ma, there's hell frozen over!"

  9. #9
    Lucefiel Guest
    First off I'd like to say that the Web Server this form will be put on is an NT IIS 3.0 Web Server.

    With that said...
    I've tried looking for Perl and ASP scripts but I can't find any that do what I want to annd, anyway don't know how to set up Perl on an NT IIS Web Server and can't test any ASP scripts on a test server before I put them up onto the real one (and I can't afford to put up untested scripts because they have a major SQL database that they can't afford to lose access to and they don't have any other servers.

    As for the filtering program being too time consuming, yes, it will because the program will need to be executed manually on every submission form (I know some C++ but not enough to make it automatic). I don't think he (the guy that'll be in charge of collecting the submission forms) has the time to stop what he's doing every time he gets a new submission.

    Actually the form is completely of my make, but judging from the context of your comment, thanks. That is the extent of my JavaScript knowledge though (well, I can make image rollovers too, but that's it).

    ------------------
    May the best of your past be the worst of your future.

  10. #10
    Lucefiel Guest
    What do I need to do (if anything) to enable PHP on an NT Web Server?

    ------------------
    May the best of your past be the worst of your future.

  11. #11
    per©oDåN Guest
    First off:

    ...anyway don't know how to set up Perl on an NT IIS Web Server...
    Perl is VERY easy to install on an NT machine. (I have used Active State's implementation of it many times)...

    ...this form will be put on is an NT IIS 3.0 Web Server...
    THERE ARE cgi's out there for Wintel boxes... they are just WAY harder to find than *nix/apache solutions. I went with MailPost way back when I was starting... It's free for a while and works OK... there are better, but not that cheap/free/easy to find. I think I wound up paying for it eventually for some reason... it was like cheap, thought... You might be able to find something better... keep looking... In cgi-land, the Internet is not NT friendly...

    the filtering program being too time consuming, yes, it will because the program will need to be executed manually on every submission
    You don't have to make the application automatic... that's what the "action" part of the <form> tag specifies... IN IIS, you would need execute or script access enabled wherever you put the app you write/borrow, and it gets called by the client machine every time they hit "submit" (that's why you specify the URL to the app in the 'action' parameter...)

    [quote]
    well, I can make image rollovers too, but that's it
    [quote]

    Hey, rollovers are cool! (it's where everybody starts after they do the 'hello world' alert)

    What do I need to do (if anything) to enable PHP on an NT Web Server
    Most NT admin-types (myself excluded this time) don't like to put PHP3/4 on the box (due to "exploits" ... as if NT istelf isn't a big exploit if you ain't got at least SP5...but that's for another thread) or let it connect to their SQL Server... plus you'd need to learn PHP, which, I grant you, probably better skillset to know than JavaScript, but anyway...

    Just install PHP4 on the box and learn the syntax if you really wanna go that way.

    -perc

  12. #12
    Lucefiel Guest
    OK, after I install ActivePerl (I have it on my home comp already) on the web server, how do I set up a virtual directory for the .pl files? I wouldn't be worried about security all that much except the admin (that's right, I'm not the admin, I'm an outside "consultant") is a 60 year old guy who didn't even know what Perl was...

    Also, with the program file (the "filter" program), how can I get it to open the E-Mail, take the attachment out, and then run the filter program on it? If I could get this to work, it would give me some time to get my CGI skills to the point where I could set up something server side.

    EDIT
    ------------------
    Or could I just send the ACTION to the program file and grab the information using cin or something similar?

    That would be even better because I could dump all the Names and Addresses into a single file that could be sorted and used "as is" instead of doing it all by hand.

    Using C++ (ANSI or not ), how can I do this? Can I just grab the information using cin or through command line arguments? Or would I have to do it completely differently?

    ------------------
    May the best of your past be the worst of your future.

    [This message has been edited by Lucefiel (edited 06 October 2000).]

  13. #13
    per©oDåN Guest
    I dunno about the programmatical aspects of cgi (C, Perl, VB), but you don't need to ust the "mailto:" directive anymore in your action statement. As you are (I think) alluding to, you can just point the form data to the URI of the program that will be handling the data. From there, I dunno how it's gonna do what it's gotta do, I always use someone else's scripts/apps. You don't necessarily need to create a single directory to put your Perl in... (Although most webservers have a cgi-bin, or cgi-win directory where scripts are centrally located and globally available for execute). If you don't put it/them there, you can use them elsewhere, you just need to make sure "Script Access" is allowed in IIS for whatever dir you DO put it in.

    -perc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •