Mansi Gupta
Mansi Gupta

Reputation: 1

I'm unable to display hyperlink via a jsp function it displays my link as text

I have below function taking text as inputs and returning text with warning symbol in a box

function showErrorMessage3(textErrorMessage1, textErrorMessage2, textInputName) {
    console.log("showErrorMessage2, textErrorMessage1=[" + textErrorMessage1 + "], textErrorMessage2=["+ textErrorMessage2 +"], textInputName=[" + textInputName + "]");
    $('.error_txt_input dd').text(textErrorMessage1+'\n'+textErrorMessage2);
    $('.error_txt_input').css('display','block');
    $('.error_txt_input').addClass(textInputName + '_Error');
}

this code should display the URL being passed in TextErrorMessage1 as a hyperlink. But it is instead displaying it as plain text.

Upvotes: 0

Views: 97

Answers (1)

Mark Melgo
Mark Melgo

Reputation: 1478

I'm assuming that $('.error_txt_input dd') is an <a> tag thus you can do this:

$('.error_txt_input dd').attr('href', textErrorMessage1);

if not then try this:

  $('.error_txt_input dd').wrap(function() {
       var link = $('<a/>');
       link.attr('href', textErrorMessage1);
       link.text(textErrorMessage1+'\n'+textErrorMessage2);
       return link;
    });

Upvotes: 1

Related Questions