JavaScript - return data to user via button click

Posted on 2011-05-04
Last Modified: 2012-05-11
Curious if code already exists out there that allow a user on button click on HTML page to run a process that wil take the data from a querystring and in loop form write it to a txt file in columns that they can save to their pc...
Columns look like:
Response/subject/phone number/message
Question by:GlobaLevel
    LVL 82

    Expert Comment

    >>take the data from a querystring and in loop form write it to a txt file
    If the browser would allow you to do that, then many people (just for the fun of it) would write an infinite loop just so the user's harddrive would run out of space. Again - just for fun :)

    To answer your question directly, the browser is not allowed to write files directly.
    LVL 13

    Expert Comment

    you can write a jquery/ajax call which can be triggered on an on click event and send off a call to a page in your favorite server side code which can then write the text file for you.
    LVL 10

    Author Comment

    R there any examples of code?
    LVL 13

    Accepted Solution

    This is written to a php page but you should be able to send it to any serverside page that you want
        var title = $('#title').val();
        $.get('choose.php',{'title':title}, function(data){

    Open in new window

    This takes a value from a form but you can pass any information that you want.
    It does an ajax call to the server side page, where it does what ever it needs and what gets returned is  anything that is printed out from the server side page.
    So you then append the data to wherever you want on the page, with this one I just appended it to the body itself.
    What I would suggest is that you get the jquery to fire on an onclick event which will then grab what ever information you need and do an ajax call to a serverside page which will do all database calls and then writes file for you. What you will return back will be a link to that file which the user can then save where ever they want.
    I might be able to be somewhat more specific if I knew what kind of server side languages you were comfortable working with so that I could find appropriate examples in that language.
    LVL 82

    Expert Comment

    The sample code you are after would depend on what server-side programming language you have.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    json example 39 83
    PHP Radio Array 4 28
    CRM 2011 Decimal Out of Range 2 20
    SharePoint CAML Query - retrieving field names 3 16
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now