How to always keep focus on TextBox?

I am trying to make focus always stay on TextBox when the user clicks on another object but it doesn’t work with Audio Files. Can anyone help please?

This is what I have so far. It works with the textarea but it doesn’t work with the Audio File when I press play or click on that area.

I am trying to make focus always stay on TextBox when the user clicks on another object but it doesn’t work with Audio Files. Can anyone help, please?

This is the code I have so far:

<html>
 <head>
<body>

[audio  mp3="Audio File Example.mp3" id="fname" onClick="mFunction()" [/audio]
  <textarea autofocus attribute  id="fname" onclick="mFunction()"  style="background-color:white;  input:focus border:5px solid green; box-shadow:0 0 50px green; font-size: 20px; body text ="#FF0000">

    </textarea>

---button onclick="myFunction()">Copy text</button>

<script>
function mFunction() {
  let x = document.getElementById("fname").focus();
 
}
</script>

</head>
</body>
</html>


I don’t think you can add a click event handler to the audio element.

You can use the standard events, like play and use that for the focus code.

document.querySelector("audio").addEventListener("play", () => {
  document.querySelector("textarea").focus();
});

You would have to do it for all the control events (seeking, volume, etc.).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.