Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to write to a txt on a server using javascript  (Read 4088 times)

0 Members and 1 Guest are viewing this topic.

alex116

  • Guest
How to write to a txt on a server using javascript
« on: January 14, 2007, 07:25:23 AM »
Hi again,

I need a function that allows you to read form variables from static HTML and write them on a txt file on the server. I need to make a database but I can only use HTML and javascript because my host allows only that.
The script must be able to read certain fields from a form and write them to a file.

Can you please help me?
Thank you very much...I am not a Javascript expert and I would like it to be complete...if possible.
I have found something while googleing this....if this can help you help me use it...maybe its not complete...or...I don't know :

function getVar(name)
         {
         get_string = document.location.search;        
         return_value = '';
        
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank space
 space = return_value.indexOf('+');
         while(space != -1)
              {
              return_value = return_value.substr(0, space) + ' ' +
              return_value.substr(space + 1, return_value.length);
                                          
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }



Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: How to write to a txt on a server using javasc
« Reply #1 on: January 14, 2007, 10:23:16 AM »
You cannot use client-side scripting (javascript) to write to a server-side file.  For that you need server-side scripting, such as PHP, Perl, ASP, Ruby, etc, etc.  It would be pretty dangerous if javascript could do things like this, since javascript can be modified at the client (browser) end.  So that would allow you to take control of someone's webserver, if what you are suggesting were possible.

Sorry!
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos

alex116

  • Guest
Re: How to write to a txt on a server using javasc
« Reply #2 on: January 15, 2007, 07:59:49 AM »
OK Rob, thank you for your time.

soybean



    Genius
  • The first soybean ever to learn the computer.
  • Thanked: 469
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 10
Re: How to write to a txt on a server using javasc
« Reply #3 on: January 15, 2007, 11:28:27 AM »
alex116, I noticed your avatar is 73,282 bytes.  Here's a resized/optimized version that's only 2,199 bytes.  Feel free to save it to your hard drive and then replace your current avatar with it.  
I believe it also looks better than what you're using now.

« Last Edit: January 15, 2007, 11:29:48 AM by soybean »