Reputation: 97
I am trying to get the value of an <select></select>
tag as set from the selected <option>
value and replace any whitespace in the value with a dash. at the moment I am just then console.log()
the value for testing but for some reason instead of selecting whitespace it is selecting and replacing lower case "s". The code I am using is:
<select onchange='var cat = this.value; var modi = cat.replace(/\s/g , "-"); console.log(modi);'>
Example: for example assume the this.value is equal to "test value"
Output: te-t value Expected Output: test-value
Upvotes: 0
Views: 73
Reputation: 280
Try this
function myFunction() {
var str = "Is this all there is?";
var patt1 = / /g;
var result = str.replace(patt1,"-");
}
Upvotes: 1
Reputation: 1697
var str = "test value";
str = str.replace(/ /g,"-");
alert(str);
Upvotes: 1