Trouble with getting content from textarea

N

Neil Cherry

First, no I'm not much of a Javascript programmer.

Basically I have a textarea that I'm entering text in. I have a
javascript function called preview. When I enter new text and send the
preview(document.getElementById('elm1')).innerHTML) I get the text
before the changes have been made. How do I get the current changed
text from the text area. Here's the html portion:

<form method="post">
<input type="hidden" name="edit" value="true">
<input type="hidden" name="modify" value="false">
<input type="hidden" name="id" value="">
<input type="text" name="title" value="Title">
<textarea class="text" cols="80" rows="20" id="elm1" name="content" WRAP="PHYSICAL">
...
</textarea>
<input type="submit" value="save">
<input type="submit" value="preview"
onclick="preview(document.getElementById('elm1')).innerHTML);return false;">

<input type="hidden" name="modify" value="true"/>
<input type="submit" value="edit" />
</form>

Preview is defined as this:

function preview(str) {
alert("Text" + str);
}

Thanks!
 
C

Captain Paralytic

First, no I'm not much of a Javascript programmer.

Basically I have a textarea that I'm entering text in. I have a
javascript function called preview. When I enter new text and send the
preview(document.getElementById('elm1')).innerHTML) I get the text
before the changes have been made. How do I get the current changed
text from the text area. Here's the html portion:

<form method="post">
  <input type="hidden" name="edit" value="true">
  <input type="hidden" name="modify" value="false">
  <input type="hidden" name="id" value="">
  <input type="text" name="title" value="Title">
  <textarea class="text" cols="80" rows="20" id="elm1" name="content" WRAP="PHYSICAL">
    ...
  </textarea>
  <input type="submit" value="save">
  <input type="submit" value="preview"
   onclick="preview(document.getElementById('elm1')).innerHTML);return false;">
This cannot be the actual code that you are executing, since it fails
initial syntax checks because you have 2 opening brackets, but 3
closing ones.

Once I correct that, I get the current text from the text box, rather
than any previous text.

Please post the actual code so that we may help you to see what's
wrong.
 
N

Neil Cherry

This cannot be the actual code that you are executing, since it fails
initial syntax checks because you have 2 opening brackets, but 3
closing ones.

Once I correct that, I get the current text from the text box, rather
than any previous text.

Please post the actual code so that we may help you to see what's
wrong.

Oddly enough that is the code and your right it shouldn't have worked
at all. (???)

I've corrected it to this:

<input type="submit" value="preview"
   onclick="preview(document.getElementById('elm1').innerHTML);return false;">

Of course the result is the same. The browser I'm testing with is
FF 3.0.13.
 
M

Martin Honnen

Neil said:
Basically I have a textarea that I'm entering text in. I have a
javascript function called preview. When I enter new text and send the
preview(document.getElementById('elm1')).innerHTML) I get the text
before the changes have been made. How do I get the current changed
text from the text area.

Access the value property of the textarea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top