I have a hidden input field that will take the value of another on keyup and I'm trying to figure out how transform the value in the hidden field to lowercase and replace spaces with hyphens.
So, if someone types "This Is A Sample" in the title input field, the identifier input field will be set to "this-is-a-sample".
<input type="text" name="title" value="This Is A Sample" />
<input type="hidden" name="identifier" value="this-is-a-sample />
To convert to lowercase :
To Replace empty space:
take a look at this example
@JSbin
To switch your text to lowercase, use the JavaScript toLowerCase() method.
See this Stackoverflow question on how to replace all the spaces with dashes using JavaScript.
This will replace all spaces with -
You can do it like this:
or if you are using JQuery:
Check