can you help me how to submit form and store the values in a .csv file and post it in another html.
here is my code...
<html>
<head>
<title>myForm</title>
<script language="JavaScript">
function WriteToFile(sText) {
first=document.myform.GivenName.value;
initial=document.myform.MiddleInitial.value;
last=document.myform.Surname.value;
f = document.getElementById("Course");
course = f.options[f.selectedIndex].text;
g = document.getElementById("year");
year = g.options[g.selectedIndex].text;
txtArea=document.myform.comments.value;
for (var i=0; i < document.myform.gender.length; i++){
if (document.myform.gender[i].checked){
var rad_val = document.myform.gender[i].value;
}
}
var fso = new ActiveXObject("Scripting.FileSystemObject");
var d = fso.OpenTextFile("d:\\guest.csv", 8, true, 0);
d.Write(first+",");
d.Write(initial+",");
d.Write(last+",");
d.Write(rad_val+",");
d.Write(course+",");
d.Write(year+",");
d.Write("COMMENTS:"+",");
d.WriteLine(txtArea);
}
</script>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<form name="myform" onSubmit="WriteToFile(this)">
Given Name:<input type ="text"name ="GivenName"value=""/><br>
Middle Initial:<input type ="text"name ="MiddleInitial"value=""/><br>
Surname:<input type ="text"name ="Surname"value=""/><br>
Gender:<br>
<input type="radio" name="gender"value = "male">Male
<input type="radio" name="gender"value = "female" >Female
<P>Course: <SELECT id="Course" SIZE="1">
<OPTION value="1" selected="selected">-
<OPTION value="2">Bachelor of Science in Information Technology (B.S.I.T)
<OPTION value="3">Bachelor of Science in Computer Sciences (B.S.C.S)
<OPTION value="4">Bachelor of Science in Information Management (B.S.I.M)
<OPTION value="5">Bachelor of Scinece in Nursing(B.S.N)
<OPTION value="6">Bachelor of Scinece in Elecetrical Engineering(B.S.E.C.E)
1. You seem to have all the code there, but don't say where you are having a problem.
2. Trying to access the filesystem (writing files to or reading from files) in Javascript is filled with all sorts of trouble. It pushes against the security model for client-side scripting. Moreover, you are assuming that you can have access to a scripting host that recognizes ActiveX objects, which means that are only dealing with users running Windows systems and using IE, for the most part. Many users are getting away from Windows, and I don't believe most Linux/Unix distros provide an ActiveX interface.
3. You appear to be in the first stages of trying to create and use a simple/primitive database, right? In that event, your best bet is to deal with all this on the server side...fewer headaches for you trying to make the client interact with its filesystem. (If you insist, you could always write some Java app and get the user to authorize it in the first instance.)
I recommend setting up your development system with Apache/MySQL/PHP/PHPMyAdmin. In a few days, you have some working scripts and are learning a lot. You might still use Javascript, but only with minimal validation or using AJAX once you have very mature scripts and your db is working.