Aniket Singh Aniket Singh - 5 months ago 9
Javascript Question

How to change the title of page after input field is filled

I want to change the title of page after user has filled the title input field in the form like stack overflow does!

here is the html code

<input type="text" id="titl" name="title" onkeyup="myFunction()" value="">


javascript function

function myFunction() {
document.title = $("#titl").val();
}


How can i achieve this?
this replaces the whole title i just want to add it like this
Title from field | Website title

Answer

Given your statement

i just want to add it like this Title from field | Website title

You can do it like this:

var origionalTitle = document.title;
function myFunction() {
    document.title = $("#titl").val() + " | " + origionalTitle;
}