Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy timed events - post values from textbox to textarea

    Good morning,

    sorry for my poor english ^_^

    Im building a standalone management tool in php and im currently locked on a timed event.
    I've created a form that insert 2 values in a mysql DB but i need to put (for some minutes) one value in a textarea too

    (trying to simplify my request), example:
    form 1
    input box name "nome"
    button "submit"

    when i click the "submit" button i need to put for "10" minutes "nome" value in a textarea "textarea1".


    I've searched on our bible "google" and the solution seems to be in "javascript" that i dont know :-(

    I've tried to do the first step (insert the text value into the textarea)

    function AddItem()
    {
    testo = document.form1.text1.value;
    document.form1.textarea1.value == document.form1.textarea1.value + testo;

    }

    and added into inputbox: onSubmit="AddItem();"


    Someone can help me pls?

  • #2
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    by the way it's:
    Code:
    document.forms.theNameOfYourForm.TheNameOfTheInput.value;

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,906
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    function AddItem() {
    testo = document.form1.text1.value;
    document.form1.textarea1.value == document.form1.textarea1.value + testo;
    }

    Well, that will put the value of textarea1 into the variable testco, and then make the value of textarea1 equal whatever it was plus testco, in other words repeat it.

    I guess that this is more or less what you are looking for:-

    Code:
    <form name = "form1">
    <textarea name = "txtarea1" id = "txtarea1" rows = "6" cols = "40" >Initial Text</textarea><br>
    <input type = "text"  name "nome" id = "nome"><br>
    
    <input type = "button" value ="Place In Textarea" onclick = "addItem()">
    
    <script type = "text/javascript">
    var tim;
    var a,b,c,d;
    var count = 0;
    var mins = 5;  // length of time in minutes to display before reversion to original text
    function addItem() {
    a = document.getElementById("txtarea1").value;
    if (count == 0) {
    d = a;  // d is the original value of the textarea before an additions
    count ++;
    }
    b = document.getElementById("nome").value;
    c = a + " " + b;
    document.getElementById("txtarea1").value = c;
    document.getElementById("nome").value = "";
    tim = setTimeout("erase()", (mins * 60000));  // revert to original text after that time.
    }
    
    function erase() {
    document.getElementById("txtarea1").value = d;  // original text
    }
    </script>

    It is your responsibility to die() if necessary… - PHP Manual
    Last edited by Philip M; 03-30-2009 at 01:58 PM.

  • Users who have thanked Philip M for this post:

    pigro (03-30-2009)

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Many thanks for your replies

    I've found a serious forum that someone reply to my questions finally!

    Thanks Philip for your code .. It's working and is the solution of my problem

    I'm trying to study it

  • #5
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ehm .. i've tested it and is working but if i wish insert the value "nome" more then one time

    for example:

    I write "Luigi" in textbox "nome", click on button and the value "Luigi" will be inserted into textarea "textarea1"

    after 2 mins, i write "Mario" in textbox "nome", click on button etc etc

    the result is that i have in "textarea1" the following text "Luigi" and "Mario" but the value "Luigi" remain 2 + 5 mins (7mins) and he will deleted at the same time of value "Mario"

    I need to put Luigi into textarea1 for 5mins and Mario too

    i hope that you have understand it ^_^

  • #6
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    another example:

    now> 16:11 i put into textarea the value Luigi

    16:13 i put into textarea the value Mario

    luigi will disappear @ 16:16
    mario will disappear @ 16:18

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,906
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Here you go (but it would have been better if you had specified this at the outset):-

    Code:
    <textarea name = "txtarea1" id = "txtarea1" rows = "6" cols = "40" ></textarea><br>
    <input type = "text"  name "nome" id = "nome"><br>
    
    <input type = "button" value ="Place In Textarea" onclick = "addItem()">
    
    <script type = "text/javascript">
    
    var atext = new Array();
    var atim = new Array()
    var otext = "This is the original text in the textarea";
    document.getElementById("txtarea1").value = otext;
    
    //var showtime = 300000;  // milliseconds = 5 minutes
    var showtime = 10000 // 10 seconds for test purposes
    
    window.setInterval("showtext()",1000);  // refresh every 1 second
    
    function showtext() {
    var now = new Date().getTime();
    var string = otext;
    for (var i =0; i <= atext.length; i++) {
    if ((atim[i] + showtime) > now) {
    string = string + " " + atext[i];
    }
    string = string.replace(/\s+/g," ");
    document.getElementById("txtarea1").value = string;
    }
    }
    
    function addItem() {
    var b = document.getElementById("nome").value;
    atext.push(b);
    var now = new Date().getTime();
    atim.push(now);
    document.getElementById("nome").value = "";
    }
    
    </script>
    Last edited by Philip M; 03-31-2009 at 09:36 AM. Reason: Slight improvement

  • Users who have thanked Philip M for this post:

    pigro (03-31-2009)

  • #8
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I'm sorry for my bad explaination

    it's work! many many thanks. i can finish my "platform" now ^_^

  • #9
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    uhm, i've found another problem

    The script is working perfectly but the function additem is called by an onclick event of a button element.

    My initial request was linked to a query into a mysql db, now if i add my php code that call an "insert query" the page don't work.

    I've searched for another solution, an emulation of submit button and i've found the follow code:

    document.form1.submit();

    the page is submitted when I insert the submit(); in AddItem function but your code doesn't work more.

    Could you please help me ?? )

  • #10
    New Coder
    Join Date
    Mar 2009
    Location
    Milan
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    FYI

    see related topic: http://www.codingforums.com/showthre...046#post802046

    I've resolved my issue, thanks Philip M for your code.

  • #11
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hai, i am trying to implement the same concept: "When a user types something in the text box it has to be stored somewhere"

    Well my situation is:

    1.) We do not have database associated to our Php Project, even the registered user names and passwords are stored in a text file and from there they are authorized.

    2.) My task is to add a comments section at the bottom of a webapge implemented in HTML and PHP.

    3.) Right now the page displays a report, i have to add a textbox or texteditor or anything at the end of the page along with a button, the purpose is to develop a comments seesion for every report and comments can be given by different users.

    4.)I tried the code you gave at the top but you know, in my situation it does nothing, as soon as i refresh the page everything gets erased.

    5.) My boss suggests me that whenever someone enters comment, the whole HTML page has to be changed and may be the comment will be stored along with the other attributes of the report.

    6.) I checked how the report is getting generated, a single function output is generating the whole report or the whole page:

    Any help or suggestions would be very grateful sir!!

    Pls help me!!


  •  

    Tags for this Thread

    Posting Permissions

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