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

Entry

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.
<script>
   var fso, f1
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f1 = fso.CreateTextFile("C:\\WINDOWS\\Desktop\\file name.txt", true);
   // Write a line.
   f1.WriteBlankLines(1);
   f1.Close();
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", 
ForReading);
   s = ts.ReadAll();
   s1 = s+MyWords
   ts.Close();
   f1 = fso.CreateTextFile("C:\\WINDOWS\\Desktop\\file name.txt", true);
   // Write a line.
   f1.WriteLine(s1);
   f1.Close();
}
</script>
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" 
multiple>
        <OPTION selected> Select An Option</OPTION>
        <OPTION value="What ever you would like to be writen to the 
file.">seletion 1</OPTION>
	</SELECT></FORM>
<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.
From:OneDogAmI
OneDogAmI Productoins
www.onedogami.8m.com
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com