Forum Moderators: open

Message Too Old, No Replies

insert hyperlink (like BB code)?

         

mattpointblank

12:00 am on Nov 22, 2005 (gmt 0)

10+ Year Member



Hey all,

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?

rocknbil

8:00 pm on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that the passed parameter is the form OBJECT, not just name, value (contents) or reference. This can be accessed by document.formname.textareaname, document.forms[formnumber].textareaname, whatever, it has to be the object itself.

<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. :-)

mattpointblank

10:14 am on Nov 23, 2005 (gmt 0)

10+ Year Member



Thanks! After a little modification this worked great, I'm very grateful.