Jake Barnes wrote:
> RobG wrote:
>
>>No it doesn't, you are still using your flawed script to get the
>>innerHTML of a textarea element instead of the value property in several
>>places. Forget about innerHTML, use DOM.
>
>
> Why do you keep saying that? I'm not clear where in my script I'm doing
> what you say. I've reversed the code from the way it was before. I now
> get the value of the textarea first. If that returns nothing, I then
> get try to get the innerHTML of the textarea. I figure the first should
> work in most browsers, and the second will work in IE.
>
> Anyway, could you explain how that throws off what HTML shows up on te
> page here?
>
> http://www.publicdomainsoftware.org/ajaxExperiment.htm
>
Here is the start of your askForInput function with added comments:
function askForInput(introText, exampleText) {
var divRef = getRefToInputDiv();
divRef is a reference to the DIV element with id="inputDiv".
var communicationBoxRef =
document.getElementById("communicationBox");
communicationBoxRef is a reference to a div too.
communicationBoxRef.style.display = "block";
communicationBoxRef.appendChild(divRef);
For some reason you chose to move inputDiv to become a child of cBoxRef,
it could be coded as a child in the first place but maybe there is a
reason. Then you only need to show/hide the outer cBoxRef.
divRef.style.display = "block";
var area = document.getElementsByTagName('TEXTAREA')[0];
You get a reference to the text area using getElementsByTagName, but
you've given it an ID, so why not use that (as you do a couple of lines
later)? Also, it would be very easy to put the text area into a form,
then pass this.form from the button. Now you can reference the text
area using the form's elements collection - simpler and easier than
either getElementsByTagName or getElementById.
area.value = exampleText;
This sets the value of the text area to exampleText, nothing further is
required.
var divRef = document.getElementById("inputBox");
Now divRef is overwritten with a reference to the text area element with
id="inputBox", the same element as that referenced by 'area'. area and
divRef refer to the same element, until someone inserts another textarea
element before it.
if (divRef.innerHTML == "" || divRef.innerHTML == undefined) {
divRef.innerHTML = exampleText;
}
Now you go looking at the innerHTML of the textarea. You have already
set the value when you did area.value=exampleText, why try to set it
again? Everything after area.value=... to here is redundant.
There are many other examples of replicated functionality and convoluted
logic, this is just one. For example, the very next line you change
divRef back to being a reference to inputDiv.
Anyhow, keep plugging away, I'm sure it's all clear as mud right now.
--
Rob