...

View Full Version : createTextNode



Jon W
12-01-2009, 11:19 AM
Hello, I'm working on a textarea box and I'm wanting to make it so when a user clicks on a link a BB tags much like what you see here will appear right after all of the text you just typed in. So it would be the exact same as if you were typing on this forum and asking a question and you went to the top and clicked the Wrap [PHP] tag and out comes the tags right where your pointer is at. So I got this to work just fine on IE but oddly enough it isn't working the same on net scape browsers.

http://idigteck.com/mess.php


Try it out for yourself and see what I mean. Note you have to type in some text for it to mess up.

I tried different ways of doing this and non work so far. What am I doing wrong here?




<script type="text/javascript">
function appendTag(eid) {
var txtArea = document.getElementById('txtArea');
var bbtags = new Array('', '');

var aTag = document.createTextNode(bbtags[0]);
txtArea.appendChild(aTag);
}
</script>

oesxyl
12-01-2009, 12:31 PM
<script type="text/javascript">
function appendTag(eid) {
var txtArea = document.getElementById('txtArea');
if(txtArea){
var bbtags = new Array('', '');

var aTag = document.createTextNode(bbtags[0]);
txtArea.appendChild(aTag);
}else{
alert('no element with id txtArea');
}
}
</script>


best regards

Jon W
12-01-2009, 12:47 PM
Oesxyl, thanks for your reply. Unfortunately this doesn't fix the problem that I was having. I still have the exact same problems as before.

Jon W
12-01-2009, 01:02 PM
This is what something I was trying to do.



<script type="text/javascript">
function appendTag(eid) {
var txtArea = document.getElementById('txtArea');
if(txtArea){
var bbtags = new Array('', '');

var aTag = document.createTextNode(bbtags[0]);
var txt = txtArea.value;
txtArea.value = txt+bbtags[0];
}else{
alert('no element with id txtArea');
}
}
</script>


This is working the way that I wanted. Thanks for the help. :)

Jon W
12-01-2009, 01:33 PM
Better yet. Here is the full finish script. Anyone can use this if they need a script like this.



<script type="text/javascript">
function appendTag(tagName) {
var txtArea = document.getElementById('txtArea');
if(txtArea) {

if(!txt) var txt = txtArea.value; // Get the current text and store it inside of a variable

if(!bbTags) var bbTags = new Array('','','','','');

switch(tagName) {
case 'a':
txtArea.value = txt+bbTags[0];
break;
case 'u':
txtArea.value = txt+bbTags[1];
break;
case 'img':
txtArea.value = txt+bbTags[2];
break;
case 'b':
txtArea.value = txt+bbTags[3];
break;
case 'i':
txtArea.value = txt+bbTags[4];
break;
}

}
else
{
alert('Oops I missed up.');
}
}

</script>


Thanks!

oesxyl
12-01-2009, 02:07 PM
<script type="text/javascript">
function appendTag(tagName) {
var txtArea = document.getElementById('txtArea');
if(txtArea && txtArea.value) {
// if bbTags is not declared outside of function you don't need to test it
// but if exist one you can use a local new version this way
var bbTags = new Array('','','','','');

switch(tagName) {
case 'a':
txtArea.value += bbTags[0];
break;
case 'u':
txtArea.value += bbTags[1];
break;
case 'img':
txtArea.value += bbTags[2];
break;
case 'b':
txtArea.value += bbTags[3];
break;
case 'i':
txtArea.value += bbTags[4];
break;
}

}
else
{
alert('Oops I missed up.');
}
}

</script>

also you can use a associative array and 'in' operator and get rid of switch.



var bbTags = {'url':'[url=] (][/url)','u':'','img':'','b':'','i':''};
if(tagName in bbTags){
txtArray.value += bbTags[tagName];
}


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum