Jquery Copy TextBox & Replace Spaces With Hyphens

Trying to copy the contents of a first textbox as it is typed and replace spaces with hyphens - used this code but it only replaces the first space with hyphen subsequent spaces are nor replaced … If anyone can help would appreciate, I’m not very good with JQuery … thanks …

Code:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TEST</title>
<SCRIPT language="javascript" src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></SCRIPT>






<SCRIPT type="text/javascript">//<=!=[=C=D=A=T=A=[ 
$(window).load(function(){
$("#title").on("keydown", function () {


   $("#url").val($(this).val().toLowerCase().replace(" ", "-"));
});


});//]=]=>  


</SCRIPT>


</head>


<body>
<input type="text" id="title" />
<input type="text" id="url" />


</body>
</html>

You need to replace globally. At the moment you are only changing the first space found. To do this write
.replace(/ /g,“-”) instead of your .replace(" “,”-").

The two forward slashes surround a space character, so you are saying the same thing. As an example, if you put another character instead of the space between the two slashes it will be replaced with the hyphen along your test string.