Skip to content

Instantly share code, notes, and snippets.

@RakibSiddiquee
Last active April 21, 2017 13:12
Show Gist options
  • Save RakibSiddiquee/e83424698a3bfec0f6d2d08e297b930b to your computer and use it in GitHub Desktop.
Save RakibSiddiquee/e83424698a3bfec0f6d2d08e297b930b to your computer and use it in GitHub Desktop.
To create input slug and initial from an input field
<!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>
@RakibSiddiquee
Copy link
Author

Create Slug and Initial from input value in a form using jquery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment