Jump to content

Hyperlink Tags


jcstanley

Recommended Posts

Hi

 

I am trying to create a CMS.  When inputting text into a text box how can I give the user the option make a hyperlink?

 

I guess when the form is submitted the data should be stored as text in the database but it will have the <a href....etc> tags around it.

 

Then the other question is how do you read it back to be displayed as a clickable hyperlink on the page.

 

I know that paragraphs are formatted using nl2br.  Is there something similar for hyperlinks?

 

Thanks in advance  :)

Link to comment
https://forums.phpfreaks.com/topic/102746-hyperlink-tags/
Share on other sites

There are a few bugs, but there are always going to be bugs:

 

<html>
<head>
<title>Test</title>

<script language="javascript" type="text/javascript">

function addA() {
// This gets the URL
var link = prompt('Please enter the URL you would like to link to.  (Please include the http://)','http://');
// Creates opening part of link
var open = "<a href='" + link + "'>";
// Gets selected text
var text = document.selection.createRange().text;
// Last part of link
var close = "</a>"

/*
You can output two ways.  One, replace the selected text, or append it to the document.
Right now, it does both.
*/
// Puts the entire string together
var all = open + text + close;

document.selection.createRange().text = all;


// Finds area to put output
var area = document.getElementById('inputarea');
// Outputs text
area.innerHTML = all;


}

</script>

</head>
<body>
<form name="theform" method="post">
<a href="javascript:addA();">Add A Hyperlink</a>
<textarea rows="5" cols="20">


</textarea>
</form>
<div id='inputarea'>
</div>
</body>
</html>

 

If you want to see it in action, go here: http://www.iowatelecom.net/~scarruthers/text.html

 

 

EDIT: There are several things in that script you can change.  You can make a button instead of a link (like I mentioned).  The layout can also be adjusted.  If you do not want the link added to the page, just comment out the last 4 lines of code (2 already are).

Link to comment
https://forums.phpfreaks.com/topic/102746-hyperlink-tags/#findComment-526406
Share on other sites

Thanks I will give it a try!  :)

 

There are a few bugs, but there are always going to be bugs:

 

<html>
<head>
<title>Test</title>

<script language="javascript" type="text/javascript">

function addA() {
// This gets the URL
var link = prompt('Please enter the URL you would like to link to.  (Please include the http://)','http://');
// Creates opening part of link
var open = "<a href='" + link + "'>";
// Gets selected text
var text = document.selection.createRange().text;
// Last part of link
var close = "</a>"

/*
You can output two ways.  One, replace the selected text, or append it to the document.
Right now, it does both.
*/
// Puts the entire string together
var all = open + text + close;

document.selection.createRange().text = all;


// Finds area to put output
var area = document.getElementById('inputarea');
// Outputs text
area.innerHTML = all;


}

</script>

</head>
<body>
<form name="theform" method="post">
<a href="javascript:addA();">Add A Hyperlink</a>
<textarea rows="5" cols="20">


</textarea>
</form>
<div id='inputarea'>
</div>
</body>
</html>

 

If you want to see it in action, go here: http://www.iowatelecom.net/~scarruthers/text.html

 

 

EDIT: There are several things in that script you can change.  You can make a button instead of a link (like I mentioned).  The layout can also be adjusted.  If you do not want the link added to the page, just comment out the last 4 lines of code (2 already are).

Link to comment
https://forums.phpfreaks.com/topic/102746-hyperlink-tags/#findComment-526419
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.