Forum Moderators: open
I just finished writing a content management system for my site, and some of the admins (who aren't web-savvy) have complained about having to write their own HTML.
What I offered was a JS button, like on many forums, that prompts for a url, then a text string, and then assembles the HTML and puts this in the textarea. I've googled around a fair bit and got either nothing, or far too bloated WYSIWYG results which are too extreme for our needs. Does anyone know a way I can implement this?
<a name="here"></a>
<a href="#here" onclick="addURL(document.forms[0].textareaname);">Add URL</a>
Then wherever your JS lives,
function addURL(fld) {
var currVal = fld.value;
var url = prompt('Enter the URL:','http:\/\/');
if (! url) { return; }
var txt = prompt('Enter the text for the link or press enter to use the URL as the text:','Link Text');
if (! txt ¦¦ (txt == 'Link Text')) { txt = url; }
fld.value = currVal + '\n' + '<A HREF="' + url + '">' + txt + '<\A>';
}
Replace broken pipes ¦ with actual vertical pipe.
This will append the contents of textarea with the URL. To insert it at a particular location, see bloated Javascripts you found as this is browser-dependent and requires hoop-jumping. :-)