I'm trying to get the text "Student 1, " to display in a text box but also have it as a link back to the student's page.
This code displays only the url I want but not as a link and doesn't display "Student 1 "

function getFavourite()
{

    var name = document.createElement('a');
    var linkText = document.createTextNode("Student 1, ");
    name.appendChild(linkText);
    name.title = "Student 1, ";
    name.href = "";


    $("#output").val($("#output").val() + ' ' + name);
    saveFavourites();
    loadFavourites();
}

Can anyone help with this?
Thanks.

If you wanted "Student 1, " to display in the text box, you would change line 11 to be name.title. However, the rest of what you are asking regarding placing a clickable link inside of an input element isn't going to work as far as I know. The input (textbox) element has the value property and this property will contain text, not another element such as a hyperlink.

Instead of using an input elmenent, you can use a div, and style it to look like an input box.

If you have something like
<div id='output'></div>
Then you could do this:

 function getFavourite() {
        var name = document.createElement('a');
        var linkText = document.createTextNode("Student 1, ");
        name.appendChild(linkText);
        name.title = "Student 1, ";
        name.href = "";
        $("#output").append(name);
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.