1

I am saving the form text(facebook page name) entered by the user into to database.

<form:input type="text"  path="fName" value="${bean.fName}" title="Page Name"/> 

What i want is when the user enters the fbpage name in the form text it should automatically change into fb-url. For example if user enters "google" the form text should change to "https://www.facebook.com/google". How can i achieve this by Javascript ?

1
  • you want to change the text value not to re-direct Commented Oct 4, 2016 at 5:42

3 Answers 3

3

Hello If I understand your problem that text should be change into url in the same textbox then try the below code

$("#user").change(function()  //user is textbox ID
{
$("#user").val("https://www.google.com/"+$("#user").val()); //added google you can use facebook also
 });

check below fiddle Url Fiddle Link

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to change the text-box value :

<input type='text' path='fname' id='path' value="${bean.fname}" title="Page Name" onfocusout='changeValue()'/ >

JS :

function changeValue(){
 document.getElementById('path').value = "https://www.facebook.com/"+document.getElementById('path').value; 
}

Demo

Comments

0

It can be done via jquery too. if you have input like below

<input type='text' id='url' value="" title="Page Name" onblur="getVal()"/>

jquery function

function getVal() {
   var link = "https://www.facebook.com/";
   $("#url").val(link + $("#url").val());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.