I have 3 inputs in a form and i want to save the value of input3 as C:\My Documents\(input1)\(input2).
I've tried using an <execCommand("SaveAs")> script, then use a <document.write(C:\...)> script, but the <document.write> script won't work.
Can anyone help me?

Please help,
Bladerbole

Dani AI

Generated

Browsers will not allow a page script to write directly to an arbitrary local path such as
C:\My Documents\.... As correctly explained, that restriction is part of the browser security model;
as noted, document.write only writes to the current page. Cookies were suggested by — they work for small bits of state but are limited and sent with every request. The modern, practical options are:

  • Client-side persistence for form state: localStorage or IndexedDB (persistent, per-origin) instead of cookies.
  • Generating a downloadable file (Blob + download) that the browser will prompt the user to save — the script can suggest a filename but cannot place the file silently into C:\My Documents\....
  • Server-side storage (PHP/ASP/Node) to keep subscriber lists on the server; this is required for reliable mailing lists and bulk storage.

Example: save/restore three inputs to localStorage (restores on load, updates on input):

window.addEventListener('DOMContentLoaded', () => {
  ['input1','input2','input3'].forEach(id => {
    const el = document.getElementById(id);
    if (!el) return;
    el.value = localStorage.getItem(id) || '';
    el.addEventListener('input', () => localStorage.setItem(id, el.value));
  });
});

Example: build a text file from the inputs and prompt download (browser chooses location):

const i1 = document.getElementById('input1').value;
const i2 = document.getElementById('input2').value;
const content = `C:\\My Documents\\${i1}\\${i2}\\\n`;
const blob = new Blob([content], {type:'text/plain'});
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${i1}_${i2}.txt`;
a.click();
URL.revokeObjectURL(a.href);

For collecting subscribers without a host (as asked by ), common approaches are: use a third-party form endpoint or mailing-service sign-up form, or host a tiny server-side script that appends posted data to a CSV. Minimal PHP example that appends name/email to a file (server-side):

<?php
$data = $_POST['name'].','.$_POST['email']."\n";
file_put_contents('subscribers.csv', $data, FILE_APPEND | LOCK_EX);
?>

Notes and cautions: localStorage and cookies are client-side and not suitable for confidential data; server-side storage is needed for reliable mailing lists and sending gifts. Always validate and sanitize inputs, use HTTPS, and obtain proper consent before collecting personal data. If the goal is a native-like save to a specific folder on the PC, that requires a native app or explicit user selection via browser file-picker APIs (the File System Access API) and cannot be done silently.

Recommended Answers

All 5 Replies

JavaScript is client-side code. Trying to save files locally violates the browser security model.

Document.write prints to the current HTML page, not to the hard drive, I believe. There is no way to get JavaScript to write anything to a hard drive. You will need to use a server-side language such as PHP or ASP, to save to the server's drive.

Of course, you CAN save your form values in cookies. Not all users have cookies, enabled, but that is exactly what cookies were designed to do.

Do you need help with JavaScript cookie code?

Did this work? Do you need more help? Pleave give us some feedback.

Hi Guys, I'm a brand new user to Dani Web.. I was browsing the web looking for a script somewhat like this one. I hope someone will actually look back at this and reply. Here's my query:

I have a website where people can subscribe to get daily updates. However, I recently decided to do something to boost up my subscription numbers. I decided to give away a free gift to every subscriber. The only thing is that I'm not very good at xml or php, but I know it's doable. I just want to save the addresses and the names of every subscriber. I don't have my own host, therefore I can't install anything. I was just wondering if It's possible. I know I can redirect the form action to a php function where it can create or just edit an xml document and add the strings that were entered in the form, however my form action to subscribe people, therefore I can't change it?

Is it possible to use Javascript to save the values as cookies and then write those cookies in a txt file? I know I need Java to write anything on the hard drive.

Any ideas?

Thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.