0

I have a few radio buttons in a page and I need to save their values or whatever value is selected to a file.

Here is a sample code:

 <input name="select" type="radio" value="a" />
 <input name="select" type="radio" value="b" />
 <input name="select" type="radio" value="c" />
 <input name="select" type="radio" value="d" />

Whenever the user selects one I need it saved / appended into a file.

Possible?

UPDATE:

Tried this:

<script>
  $(document).ready(function () {

$("input[name='select']").change(function(e) {
    e.preventDefault();
    $.post("zzz.html", { selectedValue : $(this).val()  }, function(response) {
        // do something with server response
        alert('saved');
    });
});



});
  </script>

Result: No Result. Nothing created / Nothing Saved.

1
  • 2
    On the server? On the client? Where? Commented Aug 6, 2011 at 0:52

4 Answers 4

2
$("button").click(function(){
    $.post('save_values.php', $("form").serialize(), function(){
             alert('saved');
    });
    return false;
});
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to save the the text to a file on your server, then you can use php.

This example checks to see if a file name has been set, and the text to log has also been set. It opens the file and appends text to it by specifying "a+".

So visiting

http://websitename.com/myfile.php?filename=test.txt&log=string to write

Will create and append the text to that file on your server. If then you want to provide the textfile to the user to download you can just use

http://websitename.com/test.txt

This code is untested

<?php
if(isset($_GET["filename"]) == true && isset($_GET["log"]) == true){
    $fp = fopen($_GET["filename"], "a+");

    if($fp !== null){
        fputs($fp, $_GET["log"] . "\r\n");
        fclose($fp);
    }
}
?>

jquery get method

$.get("myfile.php", { filename: "text.txt", log: "string to write" });

Comments

0

Assuming you want to save the selected value every time the radio group has been changed:

$("input[name='select']").change(function(e) {
    e.preventDefault();
    $.post("foo.html", { selectedValue : $(this).val()  }, function(response) {
        // do something with server response
    });
});

Comments

0

If it is on server you can submit to a servlet and open a file and write on the file.

if it is in client side you can try using this jQuery plugin http://jquery.tiddlywiki.org/twFile.html and do that...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.