auto fill forms with JS (or another scripting language)

Discussion in 'JavaScript' started by mz906, Feb 15, 2008.

  1. #1
    im working on a script for importing a small amount of data (2-3 fields)
    the values would be hard coded variables and automatically loaded into the text fields of a web form.

    i've started searching google and haven't been able to find anything usefully so far

    i'm familary with html and js but this seems alittle advanced for me, can someone point me in the right direction? provide a link? some sample code? the pro/cons of this? any input would be great :)
     
    mz906, Feb 15, 2008 IP
  2. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not just set the values in the field elements themselves? For example,

    
    <input name=TextBox1 id=TextBox1 value="Default_value">
    
    Code (markup):
    as opposed to:

    
    <input name=TextBox1 id=TextBox1>
    
    <script>
    window.onload = function() { document.forms[0].TextBox1.value = "Default_value"; };
    </script>
    
    Code (markup):
     
    vpguy, Feb 18, 2008 IP
  3. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, if the values never change then don't go through the hassle of scripting them in, just use the value attribute on the form elements to accomplish the same goal.
     
    The Critic, Feb 19, 2008 IP
  4. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The only reason you'd want Javascript for this is if these values are expected to be changed and you don't want your visitors to have the hassle of deleting the text first. There's a script floating around out there that removes the default value on mouse click or on (keyboard) focus. And actually, it doesn't even have to delete the text, but merely highlight it. Highlighted text gets replaced by whatever the next character typed in is anyway.
     
    Stomme poes, Feb 19, 2008 IP
  5. chirayu

    chirayu Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi all,

    I am looking for auto form fill up script probably in php. If any one can provide me, kindly contact me at . A javascript code can also satisfy my requirement.

    Thanks a lot in advance.
     
    chirayu, Jun 5, 2008 IP