The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> get data from html form and write into a file, javascript, get data from html form and write into a file, javascript
Daralis
post Apr 25 2012, 05:47 PM
Post #1





Group: Members
Posts: 5
Joined: 25-April 12
Member No.: 16,984



Im trying to write data retrieved from html form, but can't make it work. Please help me. Iam a newbies to this.

Thanks so so much.


<script LANGUAGE="JavaScript">
function Write(input0, input1, input2)
{
var Scr = new ActiveXObject("Scripting.FileSystemObject");
var CTF = Scr.CreateTextFile("employeefile.txt", 1, true);
CTF.WriteLine(input0 + ","+ input1 + ","+ input2);
CTF.Close();
}
function validateForm()
{
var x1=document.userform.pwd.value;
var x2=document.userform.re_pwd.value;
if (x2 == x1)
{
document.write(document.userform.empname.value)
Write(document.userform.empname.value, document.userform.user.value, document.userform.pwd.value);

}
else
{
alert("Passwords are not the same, Re-enter password");

}
}
</SCRIPT>

</head>

<body>

<table width=100% border="0">
<tr>
<td style="background-image:url(http://farm8.staticflickr.com/7092/7114162767_1c07772c85.jpg); background-size:cover;">
<p style="font-family:Britannic Bold;font-size:180%;color:#3300FF;text-align:center;"> <br /><br /> REGISTER </p><br />
</td>

</tr>

<tr>
<td style="background-color:#EEEEEE;height:700px;background-size:cover;text-align:center;">

<form ACTION="" NAME="userform" METHOD="GET" ONSUBMIT="return validateForm()">Create employee profile: <BR><br /><br />
Employee Name: &nbsp; &nbsp; <input type="name" name="empname" size="35"/><br /><br />
Username: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="logintext" name="user" size="35"/><br /><br />
Password: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="password" name="pwd" size="35"/><br /><br />
Re-enter Password: <input type="re_password" name="re_pwd" size="35"/><br /><br />

<input type="submit" value="Submit" size="35"/>
</form>
</td>
</tr>

<footer>

<tr>
<td colspan="2" style="background-color:#FFA500; width:100%; height=50px; text-align:center;">
Copyright © 2012 QGS Inc.
</td>
</tr>
</table>
</footer>

</body>
</html>

This post has been edited by Daralis: Apr 25 2012, 06:27 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 26 2012, 04:33 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



Are you really trying to write this to a file on the visitor's computer?

(As I understand it, normally javascript has no access to the local file system, for obvious reasons. Perhaps this "activeX" stuff is part of the MS virus dissemination kit, but if so it won't work in many cases.)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 26 2012, 07:12 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



A more traditional approach might be to write the data to a cookie.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Daralis
post Apr 26 2012, 10:54 AM
Post #4





Group: Members
Posts: 5
Joined: 25-April 12
Member No.: 16,984



QUOTE(Brian Chandler @ Apr 26 2012, 04:33 AM) *

Are you really trying to write this to a file on the visitor's computer?

(As I understand it, normally javascript has no access to the local file system, for obvious reasons. Perhaps this "activeX" stuff is part of the MS virus dissemination kit, but if so it won't work in many cases.)


Thanks for your response, Iam just trying to save it on my computer for now.
So, what should I do now.

Thanks,

~Thuyly
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Daralis
post Apr 26 2012, 10:56 AM
Post #5





Group: Members
Posts: 5
Joined: 25-April 12
Member No.: 16,984



QUOTE(Christian J @ Apr 26 2012, 07:12 AM) *

A more traditional approach might be to write the data to a cookie.



Im a really newbies on this. Could you show me how. Thanks.


~Thuyly
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 26 2012, 11:54 AM
Post #6


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



See for example http://www.quirksmode.org/js/cookies.html
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 26 2012, 11:50 PM
Post #7


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(Daralis @ Apr 27 2012, 12:54 AM) *

QUOTE(Brian Chandler @ Apr 26 2012, 04:33 AM) *

Are you really trying to write this to a file on the visitor's computer?

(As I understand it, normally javascript has no access to the local file system, for obvious reasons. Perhaps this "activeX" stuff is part of the MS virus dissemination kit, but if so it won't work in many cases.)


Thanks for your response, Iam just trying to save it on my computer for now.
So, what should I do now.


Where is "your computer"? Do you mean that whoever looks at the page you want them to store things on your computer? Or do you mean that you are the only person who looks at this page, and you want to save something from it? (In which case the simplest answer is to do it by hand)

Usually the point of a form is that whoever fills it in, the results are saved on the server; this requires some sort of server script.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 02:07 AM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



A couple of things. I can't get this to work with a relative path, try the full path, c:\\...

What does the second parameter (1) in the CreateTextFile() parenthesis stand for? I don't find it in MS's reference, but it doesn't stop things from working. I wonder if you don't say 'true' two times but in different ways.
http://msdn.microsoft.com/en-us/library/z9...0(v=vs.85).aspx

There's something wrong with the validation bit. The Write() function on it's own works (if the values are passed to it) provided I use the full path to the file. IE's script debugger complains that "document.userform.empname is null or not an object", but I don't see why.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 27 2012, 07:39 AM
Post #9


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Apr 27 2012, 09:07 AM) *

What does the second parameter (1) in the CreateTextFile() parenthesis stand for? I don't find it in MS's reference, but it doesn't stop things from working. I wonder if you don't say 'true' two times but in different ways.
http://msdn.microsoft.com/en-us/library/z9...0(v=vs.85).aspx

According to http://msdn.microsoft.com/en-us/library/5t...c(v=vs.85).aspx it should be a boolean value (true/false) for "overwrite", but according to the user comments the description is incorrect. Maybe an invalid value like "1" makes it behave as if "true" was used.

QUOTE
IE's script debugger complains that "document.userform.empname is null or not an object", but I don't see why.

Could it be because

CODE
document.write(document.userform.empname.value)

overwrites the whole webpage? So maybe when the Write() function tries to find "document.userform.empname" it doesn't exist anymore. See if this works better:

CODE
document.body.innerHTML+='<h2>'+document.userform.empname.value+'</h2>';

Also maybe the form submit should be cancelled with a "return false".
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 07:47 AM
Post #10


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



QUOTE(Christian J @ Apr 27 2012, 02:39 PM) *


Could it be because

CODE
document.write(document.userform.empname.value)

overwrites the whole webpage?


Yes, of course! With that line removed it works. But IE seems to require double slashes in the path (c:\\...) otherwise it complains about bad filename something something. Do you know why? I've never encountered this before.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 27 2012, 10:13 AM
Post #11


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Apr 27 2012, 02:47 PM) *

IE seems to require double slashes in the path (c:\\...) otherwise it complains about bad filename something something. Do you know why? I've never encountered this before.

How did you find out about the double slashes in the first place, from the MSDN reference? Note how the VBScript examples use a single slash, while the JScript ones use a double. Maybe it's for escaping in Jscript, but do you have to escape a backslash in the first place? unsure.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 10:17 AM
Post #12


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Yes, from the page I linked to.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 27 2012, 10:20 AM
Post #13


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE
Maybe it's for escaping in Jscript?


For example, if the first character in the filename is a "t" like in "testfile.txt", then

CODE
\testfile.txt

might be interpreted as a tab followed by "estfile.txt" without the escaping. unsure.gif See if it works with a single slash if the filename's first letter isn't one that needs to be escaped.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 11:20 AM
Post #14


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Nope. I named my test files 1.txt, 2.txt and so on.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 27 2012, 12:03 PM
Post #15


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



BTW, how much do you have to lower MSIE's security settings for this to work? And can you rewrite any text based file on the user's computer?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 12:41 PM
Post #16


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



I didn't lower anything, just has to OK the active-x prompt. But that could be different depending on your settings and version of IE I guess.

I guess you can overwrite any existing file since I overwrote the one I created several times.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 27 2012, 02:43 PM
Post #17


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Apr 27 2012, 07:41 PM) *

I didn't lower anything, just has to OK the active-x prompt. But that could be different depending on your settings and version of IE I guess.

Do you view the HTML file with the script from your local file system? The latter's security zone seems to have low security, but can't be viewed/changed unless you make changes to the registry: http://surfthenetsafely.com/ieseczone3.htm

Can't believe scripts are allowed access to users' file system in the Internet Zone. If it was this easy to hack Windows with javascript there would be an, err, pandemic. ninja.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 27 2012, 03:59 PM
Post #18


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Of course it's local and didn't make any registry changes. Don't you have your own IE by the way? tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 28 2012, 07:52 AM
Post #19


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Apr 27 2012, 10:59 PM) *

Of course it's local and didn't make any registry changes.

You don't need any registry changes, except for examining the local system's security settings.

QUOTE
Don't you have your own IE by the way? tongue.gif

I just wanted to know how dangerous MSIE really is. With your interest in activeX you seemed like an excellent guinea pig. cool.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 28 2012, 08:38 AM
Post #20


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



You said above that registry changes were needed, or so I thought.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 06:12 AM