home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2814
Discussions: 188,384, Posts: 2,243,509, Members: 232,615
Old January 28th, 2003, 08:59 AM   Digg it!   #1 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
java update a txt file

is there any script or and applet for java that can add to a text file. this is becasue my web server doent allow cgi-scripts or php.

Carl-cox- is offline   Reply With Quote
Old January 28th, 2003, 01:38 PM     #2 (permalink)
Member
 
Join Date: Dec 2001
Posts: 68
client side test file or server side? is this what you mean....

http://www.webreference.com/js/tips/001031.html

hawkman2 is offline   Reply With Quote
Old January 28th, 2003, 02:41 PM     #3 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
interesting hawkman...

We could use that script to write an environmental variable to the file, such as a visitor's IP #...
__________________
My R&D machine:

AMD 2100+ @ 2700+
Asus A7N8X-E
1GB Kingston PC333
2xWD 74GB Raptor's in SATA RAID
ATI 9700Pro w/ Zalman Heat Pipe

Emc2 is offline   Reply With Quote
Old January 28th, 2003, 03:16 PM     #4 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
yeh sort of but im a n00b when it comes to java (just learning VB ) what i want is it go gather the text from a webform text box then when i press submit it exicutes the java to right whatevers is in the text box to a txt file this is what i have so far

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function news() {
<!--
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
myActiveXObject.CreateTextFile("news.txt");
file = myActiveXObject.GetFile("news.txt");
text = file.OpenAsTextStream(ForWriting, TristateFalse);
text.Write(textbox1.value);
text.Close();
// -->
}
</SCRIPT>
</head>


<body>
<form name="form1" method="post" action="">
<input type="text" name="textbox1">
<input type="submit" value="Send" name="submit">
<script language="JavaScript">
<!-- Begin
news();
// End -->
</script>
</form>

this code runs with out any errors but doesnt up date the .txt file any suggestions ?
__________________
http://www.coxeh.com

Last edited by Carl-cox- : January 28th, 2003 at 03:27 PM.
Carl-cox- is offline   Reply With Quote
Old January 28th, 2003, 03:21 PM     #5 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
dunno...maybe since the script's in the heading you're opening, writing, and closing the file before it actually loads the page? Try experimenting with it in different locations. I'm just now learning c++ legitimately, so I'm more of a n00b than you...
Emc2 is offline   Reply With Quote
Old January 29th, 2003, 05:54 AM     #6 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
BUMP
Carl-cox- is offline   Reply With Quote
Old August 10th, 2003, 08:50 PM     #7 (permalink)
Junior Member
 
Join Date: Aug 2003
Posts: 1
Fix for your problem

put this in an HTML doc.. and watch the fun...
of course, this is pure client side script. Currently without a PHP Perl, ASP coldfusion.... something.. to pull file information you cannot write information to a server from the client.
You may be able to <SCRIPT LANGUAGE="JavaScript" runat=server> but that will only work if you server has a JS engine and you the engine is given permission to modify/add files on the server.

<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
/*var Path= 'c:\\documents and settings\\default\\desktop\\';
so you know what a path format has to be
the \\ translates to \ when javascript engine hits it*/

var Tristate = 0;
/*
0= ASCII text
-1= Unicode text
-2= system default*/

var ForWriting;
/*
8= append exsisting file
2= write exsisting file
1= read exsisting file*/

var Create= true;
/*true= if(file !exsist) {create}
false=if(file !exsist) {return error}*/
file = new ActiveXObject("Scripting.FileSystemObject");
/*declaring outside of funtion makes it global if you need to use recursive code*/
function news() {
ForWriting = 8;
text = file.OpenTextFile(/*Path+*/'news.txt', ForWriting, Create, Tristate);
text.Write(document.forms[0].textbox1.value+unescape('%0D%0A'));
/*%0D%0A is the escape code for linefeed carriage return
used this instead of a standard \n because notepad
doesnt display \n correctly. Wordpad, however, does.*/
text.Close();
}
function news2() {
ForWriting = 2;
text = file.OpenTextFile(/*Path+*/'news2.txt', ForWriting, Create, Tristate);
text.Write(document.form1.textbox1.value);
text.Close();
}
// -->
</SCRIPT>
</head>


<body>
<form name="form1" onSubmit="news();news2();return false;">
<input type="text" name="textbox1">
<input type="Submit" value="Update" name="update">
</form>
If you run this with <br>
line 1 then Update<br>
line 2 then Update<br>
line 3 then Update<br>
line 4 then Update<br>
<br>
You will get two files. <br>
news.txt looks like <br>
line 1 <br>
line 2 <br>
line 3 <br>
line 4 <br>
<br>
news2.txt looks like<br>
line 4<br>
<br>
<p>Indicating everytime the news function is called the file is added to, everytime the news2 function is called, the file is erased, then written with new data.</p>
<p>The form itself uses the onSumbit even to run the news() and news2() functions, then returns false to the form allowing it to stay on the same page. </p>
<p>By removing the action you will only run the onSubmit functions.</p>
</body>
</html>

Last edited by kilyo : August 10th, 2003 at 08:56 PM.
kilyo is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2896)
CPU wont boot (6)
3-days in and no threads about Gaza (160)
The United States Debt (20)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Recent Discussions
CPU wont boot (6)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
ACPI controller halt on boot (2)
Worth the upgrade?? (15)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 10:38 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28