Web Analytics Made Easy -
StatCounter Generate Plain Text With User Input? - CodingForum

Announcement

Collapse
No announcement yet.

Generate Plain Text With User Input?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate Plain Text With User Input?

    First off, I'm not very familiar with Javascripting, but I'm a quick learner. I'm pretty sure this can be done, but I haven't found anything online that does what I need, so I thought I'd ask for help.

    Basically I need to create a form that can accept user input and place it in a predetermined place in a 'template'.

    For example... in the 'template' there would be a line that says something along the lines of "My Name is John", where "John" is what is the user put in the form.

    The form would have multiple input fields, though I'm sure one simple script would work for most if not all of the fields, and I'd just have to change the input field name to display the different results in the 'template'.

    I'm sure I'll have more questions, but if I can get this first part to work I'd be happy with just that for now.

    Thanks in advance for any help you guys can give.

  • #2
    here is a small example:
    Code:
    <html><head><script>
    function submitForm(){
    var age = document.getElementById('age').value;
    var name = document.getElementById('name').value;
    // for this example i'l have the text display in a alert box
    alert("Welcome "+name+"\nListen, I know how old you are.....\nyou are 
    
    "+age+".\nSee! told you I knew!");
    }
    </script></head>
    <body>
    <input type="text" name="name" id="name"><br />
    <input type="text" name="age" id="age">
    <input type="button" onClick="submitForm()" value="submit form">
    </body></html>
    hope that helps
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

    Comment


    • #3
      Hmm... when I cut and paste that it doesn't do anything... as far as I know I don't have anything disabled that would prevent the code from working.

      Getting the result as an alert box wouldn't really work that well for this particular case though.

      I did find this tutorial where you type in the box, and the text you put there takes over the "Type something into text box" text on the page, something like this would be perfect if I could figure out a way to adopt this idea for multiple input boxes where the information you input is displayed in another section... say for example all the input boxes with lables are on one side of a table, and the resulting text is displayed on the other side.

      Comment


      • #4
        well i don't know what your issues with my script was (worked fine for me).
        it could however easily be adapted to what you want. lets show you:

        <html><head><title>test</title><script>
        var output = "this is the text for the body of the document. it can be formatted

        using html <b>tags</b> like so.<br /> to display the user information in here like

        the name (yours is {NAME}) I have used replace strings. Another example is your

        age, which by the way you entered {AGE}. Well I hope this helps!";
        function init(){
        var container = document.getElementById('outputDiv');
        container.innerHTML = output;
        }

        function doUpdate(){
        var uage = document.getElementById('age').value;
        var uname = document.getElementById('name').value;
        var container = document.getElementById('outputDiv');
        output = output.replace("{NAME}", uname);
        output = output.replace("{AGE}", uage);
        container.innerHTML = output;
        }
        </script></head>
        <body onload="init()">
        <input type="text" name="name" id="name"><br />
        <input type="text" name="age" id="age">
        <input type="button" onClick="doUpdate()" value="update text">
        <br /><hr><br />
        <div id="outputDiv"></div>

        </body></html>



        works in IE on WinXP + SP1

        I havn't tested it on any other machine / browser.
        public string ConjunctionJunction(string words, string phrases, string clauses)
        {
        return (String)(words + phrases + clauses);
        }
        <--- Was I Helpfull? Let me know ---<

        Comment

        Working...
        X