thepip3r
03-23-2005, 04:09 PM
Overall Purpose: I want a clickable button that inputs preformatted text into a submission field and the button should know whether it's open or closed...
Working Now: On the click of a hyperlink, I can get the text to display in the submission field like I want.
Problem: If the button has already been clicked and it's clicked again, the same information shows instead of adding a close tag to it.
This works:
in the head
<script>function addColor(color, chat, text) {
var revisedMessage;
var currentMessage = document.chat.elements[text].value;
revisedMessage = currentMessage+color;
document.chat.elements[text].value=revisedMessage;
document.chat.elements[text].focus();
return;
}
</script>
in the body
<a href="javascript:void[0];" onClick="addColor(':blue:','chat','text');">blue</a>
Right now the above script when the hyper link named, "blue" is clicked, it writes ":blue:" to the screen. What I still need to do is close ":blue:" somehow and I want it to happen if "blue" is clicked. If "blue" gets clicked a second time, it should write "/:blue:" to the screen or something like that.
I've tried this:
<script>function addColor(color, chat, text) {
if (color == openTag) {
closeTag = "/";
color = closeTag+color;
}
var revisedMessage;
var currentMessage = document.chat.elements[text].value;
revisedMessage = currentMessage+color;
document.chat.elements[text].value=revisedMessage;
document.chat.elements[text].focus();
var openTag = color;
return;
}
</script>
but no love... can anyone help?
Working Now: On the click of a hyperlink, I can get the text to display in the submission field like I want.
Problem: If the button has already been clicked and it's clicked again, the same information shows instead of adding a close tag to it.
This works:
in the head
<script>function addColor(color, chat, text) {
var revisedMessage;
var currentMessage = document.chat.elements[text].value;
revisedMessage = currentMessage+color;
document.chat.elements[text].value=revisedMessage;
document.chat.elements[text].focus();
return;
}
</script>
in the body
<a href="javascript:void[0];" onClick="addColor(':blue:','chat','text');">blue</a>
Right now the above script when the hyper link named, "blue" is clicked, it writes ":blue:" to the screen. What I still need to do is close ":blue:" somehow and I want it to happen if "blue" is clicked. If "blue" gets clicked a second time, it should write "/:blue:" to the screen or something like that.
I've tried this:
<script>function addColor(color, chat, text) {
if (color == openTag) {
closeTag = "/";
color = closeTag+color;
}
var revisedMessage;
var currentMessage = document.chat.elements[text].value;
revisedMessage = currentMessage+color;
document.chat.elements[text].value=revisedMessage;
document.chat.elements[text].focus();
var openTag = color;
return;
}
</script>
but no love... can anyone help?