I have two html text input, out of that what ever user type in first text box that need to reflect on second text box while reflecting it should replace all spaces to semicolon. I did to some extant and it replacing for first space not for all, I think I need to use .each function of Jquery, I have used .each function but I didn't get the result see this
HTML :
Title : <input type="text" id="title"><br/> Keyword : <input type="text" id="keyword">
Jquery:
$('#title').keyup(function() { var replaceSpace = $(this).val(); var result = replaceSpace.replace(" ", ";"); $("#keyword").val(result); });
Thanks.
A simple solution is to create an auxiliary string and copy characters one by one. Whenever space is encountered, place %20 in place of it. A better solution to do in-place assuming that we have extra space in the input string. We first count the number of spaces in the input string.
Use the String. replace() method to remove all whitespace from a string, e.g. str. replace(/\s/g, '') . The replace() method will remove all whitespace characters by replacing them with an empty string.
The easiest approach to remove all spaces from a string is to use the Python string replace() method. The replace() method replaces the occurrences of the substring passed as first argument (in this case the space ” “) with the second argument (in this case an empty character “”).
var result = replaceSpace.replace(/ /g, ";");
Here, / /g
is a regex (regular expression). The flag g
means global. It causes all matches to be replaced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With