I want to randomize user input string using sort() function..
but it's not working properly. Can anybody help me solving this problem?
function getAndSetVal() {
  var txt1 = document.getElementById('txt').value;
  document.getElementById('txt2').value = txt1;
}
// get value
function getVal() {
  var txt = document.getElementById('txt').value;
  alert(txt);
  txt1.sort(function() {
    return .5 - Math.random();
  });
}<input type="text" id="txt" name="txt" onclick="this.value = '' " />
<button onclick="getAndSetVal();">Get Value</button>
<input type="text" id="txt2" name="txt" onclick="this.value = '' " /> 
     
    