Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Title filed
- <input name="title" type="text" class="form-control" placeholder="Enter title" onload="convertToSlug(this.value)" onkeyup="convertToSlug(this.value)">
- Slug field
- <input name="slug" type="text" class="form-control" id="slug-text" placeholder="web-developer">
- Script
- <script>
- function convertToSlug(str) {
- //replace all special characters | symbols with a space
- str = str.replace(/[`~!@#$%^&*()_\-+=\[\]{};:'"\\|\/,.<>?\s]/g, ' ').toLowerCase();
- // trim spaces at start and end of string
- str = str.replace(/^\s+|\s+$/gm, '');
- // replace space with dash/hyphen
- str = str.replace(/\s+/g, '-');
- //return str;
- document.getElementById("slug-text").value = str;
- }
- </script>
Add Comment
Please, Sign In to add comment