i need to run the function changePageTitle()
if the textbox with the ID "title" is empty and if not then run newPageTitle = "please choose title" document.title = newPageTitle;
here is my code (I am trying to make something that changes the title of the page to what ever I put in the text box)
<html>
<head>
<title>
please choose title
</title>
</head>
<body>
<input type="text" id="title" size="150" oninput="changePageTitle()">
<br>
<button onclick="changePageTitle()">
*click me if page title doesn't change
</button>
<script type="text/javascript">
function changePageTitle() {
newPageTitle = document.getElementById('title').value;
document.title = newPageTitle;
}
const interval = setInterval(function(){
//here is where I want to put the check
}, 1000);
</script>
</body>
</html>
2
Answers
Will return true if the input is empty.
Is that what you’re after?
Simply check the variable directly; you already have an event handler which will be fired on input so
setInterval
is unnecessary.Try it: