faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

51 of 64 people (80%) answered Yes
Recently 8 of 10 people (80%) answered Yes


How do I use JScript to take multiple values in a HTML select menu and save them all as a ram file to be used as a playlist?

Apr 4th, 2008 20:35
ha mo, OneDogAmI,

Well, it seems that I was able to figure out my own problem.
If anyone else needs help with this here is the solution. 
How to Creating a text file to include the values of a select menu. 
The below script is in JScript. 
 The first part of the script "before the function call" 
creates a text file with a specified name to the desktop  
of a computer not using the user profiles.
first assign your variables.
fso: file system object
f1: file 1
Create your file system object.
Create the file to the path specified. The "true" attribute
allows the file to be written to.
Write a blank line to the first column. I did this because
I received an error if I did `nt.
Close the file you created.
The  Next section is from the function to the next  ts.close() function.
It will combine the value currently entered with previous values.
Create a function with the name you wish to refer to it with.
Assign your variables:
Mywords: is the value from the select menu.
fso: file system object
f1: file 1
ts: file system object 2nd
s: store "stores info to be written to s1
s1: values from select menu + Value from read text file.
ForReading: to set the write attribute to false.
Create the file system object.
Open the file that was created before the function.
Read the opened txt file and store it as s.
Store the value of the file and the value currently entered
from the select menu as S1.
Close the text document you opened.
This section takes all the values and enters them on separate
lines into the text file you created.
Open a text file to be written to. Name it the same as the
file you created in the first section.
Write the value of s1 to the file.
Close the File.
   var fso, f1
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f1 = fso.CreateTextFile("C:\\WINDOWS\\Desktop\\file name.txt", true);
   // Write a line.
function CreatAList(){
   var MyWords = document.Picks.Selections.value
   var fso, f1, ts, s, s1;
   var ForReading = 1;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   // Read the contents of the file.
   ts = fso.OpenTextFile("C:\\WINDOWS\\Desktop\\file name.txt", 
   s = ts.ReadAll();
   s1 = s+MyWords
   f1 = fso.CreateTextFile("C:\\WINDOWS\\Desktop\\file name.txt", true);
   // Write a line.
This is the form used.
Form name is "Picks" and select name is "selections".
The value is whatever you want to be written to the text file.
The button has an event handler that will call the function above
to save each entry.
<FORM name="Picks" target="_parent"><SELECT name="Selections" size="5" 
        <OPTION selected> Select An Option</OPTION>
        <OPTION value="What ever you would like to be writen to the 
file.">seletion 1</OPTION>
<BUTTON onclick="javascript:CreatAList();">Add</BUTTON>
The only problem I have encountered is that the text file will
have a blank line at the beginning of it. This did not disturb my 
application due to the fact it ignores extra space.
OneDogAmI Productoins