Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>min and max length</title>
  <style>
    p {color: red;}
  </style>
</head>
<body>
<form action="#">
  <input type="text" id="inputField" placeholder="value" name="name" onblur="validateLength(1, 20, this.form, document.getElementById('msg'));">
  <p id="msg"></p>
</form>
</body>
</html>
 
function validateLength(min, max, lengthParameter, msgText) {
  var strLength = lengthParameter["name"].value.length;
  
  if (strLength < 1 || strLength > 20) {
    msgText.innerHTML = "請填入 " + min + " 到 " + max + " 個字";
    return false;
  } else {
    msgText.innerHTML = "完成任務";
    return true;
  }
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers