I have text area for user to write article. For user I use this javascript I found from Google search :
<script type="text/javascript">
function getSelection(ta)
{ var bits = [ta.value,'','',''];
if(document.selection)
{ var vs = '#$%^%$#';
var tr=document.selection.createRange()
if(tr.parentElement()!=ta) return null;
bits[2] = tr.text;
tr.text = vs;
fb = ta.value.split(vs);
tr.moveStart('character',-vs.length);
tr.text = bits[2];
bits[1] = fb[0];
bits[3] = fb[1];
}
else
{ if(ta.selectionStart == ta.selectionEnd) return null;
bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
}
return bits;
}
function matchPTags(str)
{ str = ' ' + str + ' ';
ot = str.split(/\[[b|u|i|url].*?\]/i);
ct = str.split(/\[\/[b|u|i|url].*?\]/i);
return ot.length==ct.length;
}
function addPTag(ta,pTag)
{ bits = getSelection(ta);
if(bits)
{ if(!matchPTags(bits[2]))
{ alert(' Invalid Selection
Selection contains unmatched opening or closing tags.');
return;
}
ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
}
}
function bbUrl(){
document.test_form.test_textarea.value+="["+prompt("Text of link:")+"](+prompt("URL:")+)"
}
</script>
Above the textarea, here’s the code :
<fieldset>
<button onclick="addPTag(document.getElementById('text'),'b')"><b>Bold</b></button>
<button onclick="addPTag(document.getElementById('text'),'i')"><i>Italic</i></button>
<button onclick="addPTag(document.getElementById('text'),'u')"><u>Underline</u></button>
<button onclick="addPTag(document.getElementById('text'),'url')"><url>URL</url></button>
</fieldset>
All the entry posted via this client side then are parsed with BB Code function. All works well.
What I want is :
- How to create popup window when user click on the URL button to ask the title and the link.( exactly the way BB Code in this dear Kirupa Forum works) - so the result will look like this :
<a href="my_link">title
</a>
- I’d like to ask the same thing for email link.
I don’t mind if the suggestion you will give me is to use different Javascript than above.
Thanks a lot