3
I’m trying to do something kind of like this:
$('button').on('click', function() {
obj = {};
$('pseudoform').find('input,textarea').each(function() {
obj[$(this).attr('name')] = String($(this).val());
});
json = JSON.stringify(obj);
$('input[name=proof]').val(json);
alert('Queria que baixasse: ' + json);
});
textarea,
input,
button {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pseudoform>
<label>Titulo:
<input type="text" name="title" value="um valor">
</label>
<label>Descrição:
<textarea name="desc">qualquer</textarea>
</label>
<input type="hidden" value="123456" name="challenge">
<input type="hidden" value="999999" name="nonce">
</pseudoform>
<form target="#">
<input type="hidden" value="{valor aqui}" name="proof">
<button>Baixar</button>
</form>
The idea is that the value
of proof
is dynamically defined with a json. This json would have the values of all inputs that exist on top of it, within the pseudoform
.
The other step would be for the user to download the content by clicking on the "download", this is the question.
How can I make Javascript, in the browser, force the user to download this content ({"title":"um valor","desc":"qualquer","challenge":"123456","nonce":"999999"}
) when you click on "download"?
The reason for the user to download what he writes himself is that I need the user to subscribe to the content using Opengpg, with some smartcard. The server should only receive information from json (which is in input) and signature (Armored Detached Signature file) of this json.