www.webdeveloper.com
Results 1 to 8 of 8

Thread: [Help Needed] Automatic text-box filling?

  1. #1
    Join Date
    Aug 2013
    Posts
    57

    [Help Needed] Automatic text-box filling?

    Hello,

    There is a JS code, for example sending Private Messages on a forum.

    But when people click a button, they were reffered to the Private Message send box, but the name to send to and content are already filled.

    I want to use this for a kind of report button.
    But how do you make sure every profile or page have it?

    Thanks for reading,

    Niely,

  2. #2
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,113

    Cool Solution

    I'm not sure exactly what you are looking for, but this is what I think you are after:

    http://jsfiddle.net/JCDJh/1/

  3. #3
    Join Date
    Aug 2013
    Posts
    57
    Quote Originally Posted by donatello View Post
    I'm not sure exactly what you are looking for, but this is what I think you are after:

    http://jsfiddle.net/JCDJh/1/
    I mean that the boxes:

    Name:
    E-mail:
    ...

    Fill automatic with a name.

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,113

  5. #5
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,113
    The user will probably be logged in, so this data would be captured somewhere...

    Enter your name in the box in the bottom right square that says, "What is your name?" This is akin to logging in.
    Then click the button next to it. It will automatically fill the field that says name and email.
    Try it.

    http://jsfiddle.net/JCDJh/3/

  6. #6
    Join Date
    Aug 2013
    Posts
    57
    Quote Originally Posted by donatello View Post
    The user will probably be logged in, so this data would be captured somewhere...

    Enter your name in the box in the bottom right square that says, "What is your name?" This is akin to logging in.
    Then click the button next to it. It will automatically fill the field that says name and email.
    Try it.

    http://jsfiddle.net/JCDJh/3/
    <html>
    <head>
    <script type="text/JavaScript">
    function fillinform(){
    var user = document.getElementById("user").value
    document.getElementById("name").value =
    document.getElementById("name").defaultValue = ;
    document.getElementById("email").defaultValue = user + 'example@gmail.com';
    document.getElementById("message").defaultValue = 'To Whom it may concern:\n I would like to file a complaint...';

    }
    </script>
    </head>
    <body>
    What is your name? <input type="text" id="user" /><input type="submit" onClick="fillinform();return false" value="Contact us" /><br /><br />
    <br />
    <table>
    <tr><td>Name: </td><td><input type="text" id="name" /></td></tr>
    <tr><td>email: </td><td><input type="text" id="email" /></td></tr>
    <tr><td>Name: </td><td><textarea id="message" cols="30" rows="3"></textarea></td></tr>
    <tr><td>&nbsp;</td><td align="right"><input type="submit" value="Send email" />
    </table>
    </body>

    </html>

    Do you mean this?
    Where must I write the things I want that show up automatic in the boxes? :P

  7. #7
    Join Date
    Oct 2012
    Posts
    78
    Hello please use the CODE tags to surround your code so it's easier to read.

    Code:
    <html>
    <head>
    <script type="text/JavaScript">
    function fillinform(){
    var user = document.getElementById("user").value 
    document.getElementById("name").value = 
    document.getElementById("name").defaultValue = ;
    document.getElementById("email").defaultValue = user + 'example@gmail.com';
    document.getElementById("message").defaultValue = 'To Whom it may concern:\n I would like to file a complaint...';
    
    }
    </script>
    </head>
    <body>
    What is your name? <input type="text" id="user" /><input type="submit" onClick="fillinform();return false" value="Contact us" /><br /><br />
    <br />
    <table>
    <tr><td>Name: </td><td><input type="text" id="name" value="Alan"/></td></tr>
    <tr><td>email: </td><td><input type="text" id="email" value="google@google" /></td></tr>
    <tr><td>Name: </td><td><textarea id="message" cols="30" rows="3"></textarea></td></tr>
    <tr><td>&nbsp;</td><td align="right"><input type="submit" value="Send email" />
    </table>
    </body>
    
    </html>
    If you know what you want already filled in e.g. you want the name field to already have the name alan just assign the element a value of alan.
    I assume you want some sort of auto-fill based on a refer link or account logged in. So if George was logged in all the name textboxes would be filled in with George. This would be done with PHP and sessions.

  8. #8
    Join Date
    Aug 2013
    Posts
    57
    ... I already got it.

    I just had to put it between <textarea></textarea> Thanks anyway!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles