...

View Full Version : help with saving form to html



faheja
12-01-2006, 06:44 PM
Hey all,

Well First off let me explain what im trying to do.. I have a form which i made in html..
just something like

first name
last name
city
state

thats just a example.. but you input your info into a text box..

At the bottom of the form theres a textbox called "number" and a submit button.

i need it to be able to reconize the name they enter and save it as a *.html in a random directory

so if they enter 123 and click submit

it saves to C:\files\123.html


i cant get it to work.. does anyone have any ideas?


thanks!!!

- Jonathan

faheja
12-01-2006, 07:20 PM
this page will be running offline.. just something that a customer can use to create html files..

doesnt need to upload or anything.. just save to a directory

harbingerOTV
12-02-2006, 03:34 AM
okay heres the deal. I can srt of do it two ways. one way they have to manually save the page but it works. the second is IE only and it saves itsself.

the second using code from Bazz ( http://www.codingforums.com/archive/index.php?t-59137.html )

all browsers sort of working:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>|</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script LANGUAGE="JavaScript" type="text/javascript">
function display() {
DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=300,height=200')
message = "<b>name: </b>" + document.form1.name.value + "<br>";
message += "<b>email: </b>" + document.form1.email.value + "<br>";
message += "<b>comments: </b>" + document.form1.comments.value + "<br>";
DispWin.document.write(message);
}
</script>
<style type="text/css">
form, input, textarea {
font: 600 .8em tahoma, verdana, sans-serif;
color: #000;
padding: 4px;
width: 252px;
}
input, textarea {
font-size: 100%;
}
textarea, input {
background: #A4D6EF;
border: 2px solid #182B4F;
width: 240px;
margin: 0 0 8px 0;
}
.sub {
cursor: hand;
width: 100px;
float: left;
font: 600 .8em tahoma, verdana, sans-serif;
}
.sub1 {
cursor: hand;
width: 100px;
float: right;
font: 600 .8em tahoma, verdana, sans-serif;
}
form *:hover, form *:focus {
background: #9d3;
}
.sub:focus, .sub1:focus {
background: #A4D6EF;
}
</style>
</head>
<body>
<form name="form1">
Name:<br />
<input type="text" name="name"></input><br />
Email:<br />
<input type="text" name="email"></input><br />
Comments:<br />
<textarea name="comments"></textarea><br />
<input type="submit" value="View Data" class="sub" onClick="display();"></input><input type="reset" value="Clear Fields" class="sub1"></input><br />
</form>
</body>
</html>


IE only


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<link rel="stylesheet" type="text/css" href="" />
<script type="text/javascript">

function makeTextFile()
{
var sfo=new ActiveXObject('scripting.FileSystemObject');
var fname=document.getElementById('f_name').value;
var isFile=sfo.FileExists(fname+".html");

if(isFile)
{
alert("A file by that name already exists, please choose another file name.");
return;
}

var floc=sfo.CreateTextFile(fname+".html")
floc.Write("<html>\n");
floc.Write("<head>\n");
floc.Write("</head>\n");
floc.Write("<body>\n");
floc.Write(document.getElementById('u_name').value+"<br>");
floc.Write(document.getElementById('u_email').value+"<br>");
floc.Write(document.getElementById('u_comments').value+"<br>");
floc.Write("</body>\n");
floc.Write("</html>");
floc.Close();
alert("Your file is located on your desktop.");

}

</script>
<style type="text/css">
form, input, textarea {
font: 600 .8em tahoma, verdana, sans-serif;
color: #000;
padding: 4px;
width: 252px;
}
input, textarea {
font-size: 100%;
}
textarea, input {
background: #A4D6EF;
border: 2px solid #182B4F;
width: 240px;
margin: 0 0 8px 0;
}
.sub {
cursor: hand;
width: 100px;
float: left;
font: 600 .8em tahoma, verdana, sans-serif;
}
.sub1 {
cursor: hand;
width: 100px;
float: right;
font: 600 .8em tahoma, verdana, sans-serif;
}
form *:hover, form *:focus {
background: #9d3;
}
.sub:focus, .sub1:focus {
background: #A4D6EF;
}
</style>

</head>
<body>
<form name="form1">
Name:<br />
<input type="text" id="u_name"></input><br>
Email:<br />
<input type="text" id="u_email"></input><br>
Comments:<br>
<textarea id="u_comments"></textarea><br>
File Name:<input type="text" id="f_name" ></input><br>
<input type="button" onclick="makeTextFile();" value="Save" class="sub"></input><input type="reset" value="Clear Fields" class="sub1"></input><br />
</form>


</body>
</html>

I looked around and here's a good listing of all the ways to use FileSystemObject.
http://www.devguru.com/technologies/vbscript/quickref/filesystemobject.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum