js select text in input code example

Example 1: get selected text js

// Get highlighted text this way:

window.getSelection().toString()

Example 2: javascript select input text on focus

focusMethod = function getFocus() {           
  document.getElementById("myTextField").focus(); //select the input textfield and set the focus on it
}

Example 3: How to get the input from a textbox javascript

document.getElementById("YourTextBoxId").value

//This code will get the input from a textbox
//Make sure to change "YourTextBoxId" with the id of your textbox