Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to get a code in which users enter in their username and it creates a html file for them. I'm having a hard time getting the code to work and would appreciate some help. Also, if I were to upload this code, would it work or do I have to do something serversided?

<.html>
<.head>
<.title><./title>
<./head>
<.body>
<.script>
function WriteToFile(var userName) {
    //set fso = CreateObject("Scripting.FileSystemObject");  
    //var userName = document.getElementById('user_name').value;
    File file = new File(userName + ".html");
    //set newFile = fso.CreateTextFile(userName + ".html");
    //BufferedWriter output = new BufferedWriter(new FileWriter(file));
    //output.write("test");
    //output.close();
}

<./script>
<.form action="">
<.p>
User name: <.input type="text" id="user_name">
<.input type="submit" value="Create new page" onclick="return WriteToFile(user_name);">
<./p>
<./form>
<./body>
<./html>
share|improve this question
1  
Javascript is not java –  mguimard Apr 25 at 14:41
    
Someone correct me if I am wrong, but Javascript can't write to files. You can use AJAX to call a PHP script which creates temporary file on the server and then download it on post-back. But that's a lot more involved. –  Kivak Wolf Apr 25 at 14:42
    
You are writing Java. You need to write Javascript. –  TheShellfishMeme Apr 25 at 14:43
    
@Kivak Wolf You are right. Javascript cannot write files. Do you really want to write in a file ? Don't you just want to load the generated html in the page ? If you really want to write in a file, then Kivak solution would work i guess –  Larta Apr 25 at 14:47
1  
Actually, you can do this with javascript only, no need to have an external server. There are many way to achieve this, some ways could be found here stackoverflow.com/questions/13405129/… –  mguimard Apr 25 at 15:23
show 3 more comments

1 Answer 1

It would probably be easier to set up a small database which gets populated with the user's information, then create a template website which displays data from the user's table in the database.

share|improve this answer
    
Do you know if that could be done with javascript or would I need something like PHP –  Jay Apr 25 at 16:18
    
You would need to use PHP, but it's very simple! –  KiaShakiba Apr 25 at 18:52
    
Or, if you want to stay away from database programming, you could use PHP to output the new file (see here) with this code at the top of your page: <?php if($_POST['user_name']){ //make file } ?> –  KiaShakiba Apr 25 at 19:02
    
Sorry, I forgot the isset() around the post statement, in the if. –  KiaShakiba Apr 25 at 19:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.