J
Jake Barnes
I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:
http://www.publicdomainsoftware.org/ajaxExperiment.htm
Click in any box to get the controls with which you can play around.
This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox. In FireFox, whatever value is set initially in this function
becomes the only function that can later be retrieved. Obviously, that
is not what I want. If the software asks people to write in some text,
it should be what they write, and not the initial value, that is then
captured and used. What syntax do I have to use to set the initial
value to FireFox will still see the value that the user types in,
rather than the initial value set here?
function askForInput(introText, exampleText) {
var divRef = getRefToInputDiv();
var communicationBoxRef =
document.getElementById("communicationBox");
communicationBoxRef.style.display = "block";
communicationBoxRef.appendChild(divRef);
divRef.style.display = "block";
var area = document.getElementsByTagName('TEXTAREA')[0];
area.value = exampleText;
var divRef = document.getElementById("inputBox");
if (divRef.innerHTML == "" || divRef.innerHTML == undefined) {
divRef.innerHTML = exampleText;
}
var divRef = document.getElementById("inputDiv");
var firstChildNode = divRef.firstChild;
if (divRef.childNodes.length > 4) {
divRef.removeChild(firstChildNode);
firstChildNode = divRef.firstChild;
}
var newTextNode = document.createTextNode(introText);
var newLiterature = document.createElement("p");
newLiterature.appendChild(newTextNode);
var firstChildNode = divRef.firstChild;
divRef.insertBefore(newLiterature, firstChildNode);
}
function getInput() {
var divRef = document.getElementById("inputBox");
var inputText = divRef.innerHTML;
divRef.innerHTML = "";
if (inputText == "" || inputText == undefined) {
var area = document.getElementsByTagName('TEXTAREA')[0];
inputText = area.value;
area.value = "";
}
inputResults = inputText;
var communicationBoxRef =
document.getElementById("communicationBox");
var lastChildInCommunicationBox = communicationBoxRef.lastChild;
communicationBoxRef.removeChild(lastChildInCommunicationBox);
communicationBoxRef.style.display = "none";
if (nextActionToTakeAfterInput == "setTextAction")
setTextAction();
if (nextActionToTakeAfterInput == "setImageAction")
setImageAction();
if (nextActionToTakeAfterInput == "setHtmlAction")
setHtmlAction();
if (nextActionToTakeAfterInput == "setBackgroundColorAction")
setBackgroundColorAction();
if (nextActionToTakeAfterInput == "setColorAction")
setColorAction();
}
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:
http://www.publicdomainsoftware.org/ajaxExperiment.htm
Click in any box to get the controls with which you can play around.
This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox. In FireFox, whatever value is set initially in this function
becomes the only function that can later be retrieved. Obviously, that
is not what I want. If the software asks people to write in some text,
it should be what they write, and not the initial value, that is then
captured and used. What syntax do I have to use to set the initial
value to FireFox will still see the value that the user types in,
rather than the initial value set here?
function askForInput(introText, exampleText) {
var divRef = getRefToInputDiv();
var communicationBoxRef =
document.getElementById("communicationBox");
communicationBoxRef.style.display = "block";
communicationBoxRef.appendChild(divRef);
divRef.style.display = "block";
var area = document.getElementsByTagName('TEXTAREA')[0];
area.value = exampleText;
var divRef = document.getElementById("inputBox");
if (divRef.innerHTML == "" || divRef.innerHTML == undefined) {
divRef.innerHTML = exampleText;
}
var divRef = document.getElementById("inputDiv");
var firstChildNode = divRef.firstChild;
if (divRef.childNodes.length > 4) {
divRef.removeChild(firstChildNode);
firstChildNode = divRef.firstChild;
}
var newTextNode = document.createTextNode(introText);
var newLiterature = document.createElement("p");
newLiterature.appendChild(newTextNode);
var firstChildNode = divRef.firstChild;
divRef.insertBefore(newLiterature, firstChildNode);
}
function getInput() {
var divRef = document.getElementById("inputBox");
var inputText = divRef.innerHTML;
divRef.innerHTML = "";
if (inputText == "" || inputText == undefined) {
var area = document.getElementsByTagName('TEXTAREA')[0];
inputText = area.value;
area.value = "";
}
inputResults = inputText;
var communicationBoxRef =
document.getElementById("communicationBox");
var lastChildInCommunicationBox = communicationBoxRef.lastChild;
communicationBoxRef.removeChild(lastChildInCommunicationBox);
communicationBoxRef.style.display = "none";
if (nextActionToTakeAfterInput == "setTextAction")
setTextAction();
if (nextActionToTakeAfterInput == "setImageAction")
setImageAction();
if (nextActionToTakeAfterInput == "setHtmlAction")
setHtmlAction();
if (nextActionToTakeAfterInput == "setBackgroundColorAction")
setBackgroundColorAction();
if (nextActionToTakeAfterInput == "setColorAction")
setColorAction();
}