Last active
April 21, 2017 13:12
-
-
Save RakibSiddiquee/e83424698a3bfec0f6d2d08e297b930b to your computer and use it in GitHub Desktop.
To create input slug and initial from an input field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<form action=""> | |
Name: <input type="text" name="name" id="name"/><br/> | |
Slug: <input type="text" name="slug" id="slug" /><br /> | |
Initial: <input type="text" name="initial" id="initial" /> | |
</form> | |
<script type="text/javascript"> | |
$("#name").blur(function(){ // Create Author name slug and initial | |
var str = this.value; | |
$("#slug").val(str.trim().toLowerCase().replace(/ /g,'-').replace(/ /g,'-').replace(/[^\w-]+/g,'-')); | |
$("#initial").val(str.match(/\b\w/g).join('').toUpperCase()); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create Slug and Initial from input value in a form using jquery