SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Writing Java variables to a textarea via JavaScript

    Hi All,

    I have a READONLY textarea that should simply display the information from a database table. I am able to display the Java variables via out.println statements. However, I am not able to print them via JavaScript to my textarea. My need is to be able to write the variables from my java code to the textarea. I hope I explained my probelm properly. If not, please let me know what other details I should provide to be helped by you. I have given the code I have and the results I am obtaining right now and the desired results below. Any help would be greatly appreciated.

    Here is the scenario I am running. I have a log table from
    which I need to select the time, username, actionname and action
    description and write into the textarea (basically this is a
    readonly textarea where information is simply displayed).

    TextArea is created below:
    ====================

    <table>
    <td width="3%" align=right></td>
    <td align=left valign=top> <b>Existing Notes/td>

    <TD><textarea name="existing" wrap="hard" cols="70" rows="10"
    onkeypress="validateSize(this, 2000)" onchange="validateSize(this, 2000)"
    id="my_textarea_id" READONLY></textarea></TD>


    </table>

    <tr>
    <table>
    <td width="3%" align=right></td>
    <%
    int logSize = actionLog.size();
    if (logSize > 0){
    for (int j=logSize-1; j >=0; j--){
    DealStatusAction dsa = (DealStatusAction)actionLog.get(j);
    String actionNm = dsa.getActionName();
    String actionDate = dsa.getActionDate().toString() + "";
    String memo = dsa.getMemo();
    String actionPerformer = ((dsa.getLastName() == null ||
    dsa.getFirstName() == null)?""dsa.getFirstName()+" "+dsa.getLastName()));

    out.println(actionDate);
    out.println(actionPerformer);
    out.println(actionNm);
    out.println(memo);

    }
    }
    %>

    The above code produces the following results. On my screen, the following information is printed.

    Wed Mar 02 09:27:39 PST 2005 Bill Andruss Request Saved Action taken on Account Team tab. Mon Feb 28 12:04:31 PST 2005 Bill Andruss New Request Created A new deal has been created.



    I would like the information to come up in the following format within the textarea:

    Wed Mar 02 09:27:39 PST 2005 Bill Andruss
    Request Saved
    Action taken on Account Team tab.

    Mon Feb 28 12:04:31 PST 2005 Bill Andruss
    New Request Created
    A new deal has been created.


    I tried to plug in the following statements in the code as follows:

    tr>
    <table>
    <td width="3%" align=right></td>
    <%
    int logSize = actionLog.size();
    if (logSize > 0){
    for (int j=logSize-1; j >=0; j--){
    DealStatusAction dsa = (DealStatusAction)actionLog.get(j);
    String actionNm = dsa.getActionName();
    String actionDate = dsa.getActionDate().toString() + "";
    String memo = dsa.getMemo();
    String actionPerformer = ((dsa.getLastName() == null ||
    dsa.getFirstName() == null)?""dsa.getFirstName()+" "+dsa.getLastName()));

    out.println(actionDate);
    out.println(actionPerformer);
    out.println(actionNm);
    out.println(memo);

    }
    }
    %>



    <SCRIPT language="Javascript">

    document.getElementById("my_textarea_id").value = "test1\n";
    document.getElementById("my_textarea_id").value = "test2\n";
    document.getElementById("my_textarea_id").value = "test3\n";
    document.getElementById("my_textarea_id").value = "test4\n";




    </SCRIPT>

    Here is what is happening:

    In the textarea I see the word test4.

    Here are my specific questions:

    1. How do I specify the Java variable names within the JavaScript?
    2. How can I print the values as they are looped thro'? In other words get both sets of values in the order shown above.
    3. I removed the READONLY option to see if that is preventing from anything from being written to the textarea. It does not seem to make a difference except that the value printed test4 is editable (which is not what I want so I am retaining the READONLY option).
    4. I used the words test1 thro' test4 to see if I am able to see these values within the textarea.
    My intent is to see the values of the variables (actionDate, actionPerformer, actionNm, memo) witin the textarea.

    Greatly appreciate if you can provide an explanation of how to make this work and a possible code example. That would very much help a newbie like me.

    Many thanks in advance,
    Bill.

  2. #2
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following does the job for me. Thank you.

    <table>
    <td width="3%" align=right></td>
    <td align=left valign=top> <b>Existing Notes/td>


    <TD><textarea name="comments" wrap="hard" cols="70" rows="10" onkeypress="validateSize(this, 2000)" onchange="validateSize(this,2000)" id="my_textarea_id" READONLY>
    <%
    int logSize = actionLog.size();
    if (logSize > 0) {
    for (int j=logSize-1; j >=0; j--){
    DealStatusAction dsa = (DealStatusAction)actionLog.get(j);
    String actionNm = dsa.getActionName();
    String actionDate = dsa.getActionDate().toString() + "";
    String memo = dsa.getMemo();
    String actionPerformer = ((dsa.getLastName() == null || dsa.getFirstName() =
    = null)?""dsa.getFirstName() + " " + dsa.getLastName()));


    %>
    <%=actionDate%>
    <%=actionPerformer%>
    <%=actionNm%>
    <%=memo%>
    <%
    }
    }
    %>
    </textarea>
    </TD>
    </table>


Bookmarks

Posting Permissions

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