bruninhu
bruninhu

Reputation: 27

Create a hyperlink from part of a text submitted in a form

I would like to create a form that allows text to be transformed into hyperlink.

For example, StackOverflow allows us to create a link by following the syntax:

To create fancier links, use Markdown:
Here's [a link](http://www.example.com/)!

So when the form is submitted, [a link] actually becomes a link that takes you to www.example.com.

Any ideas?

Upvotes: 0

Views: 60

Answers (3)

Seif Sayed
Seif Sayed

Reputation: 803

create an

<a href="#"></a>

element and then change the href attribute and text to be

<a href="http://www.example.com"> your link </a> 

Upvotes: 1

shishir
shishir

Reputation: 851

Create a for with input field and a button and an a tag where the entered text value will be shown on button click, add jquery .attr() method to set the href value of a tag.

$(function(){
    $('#button').click(function() {  
        var inputvalue = $("#input").val();      $('a').html(inputvalue).attr("href",inputvalue);
    });
});

Upvotes: 1

sTx
sTx

Reputation: 1221

Create a form with 2 inputs(first for href and second for display name) and on submit you create a function that append or create a new "a" element with submitted href and display text.

Upvotes: 1

Related Questions