I have the following script that duplicates the content I'm entering in one field into another.
DEMO: https://jsfiddle.net/wk3nmc76/
I was wondering if it's possible I could change the 2nd field to strip spaces & make the value lowercase?
<p><input type="text" name="full_name" id="full_name" placeholder="Full Name"/></p>
<p><input type="text" name="last_name" id="last_name"></p>
$('#full_name').keyup(function(){
$('#last_name').val(this.value);
});
To achieve this you can use a combination of toLowerCase() and a regular expression to remove all the spaces. Try this:
$('#full_name').keyup(function() {
$('#last_name').val(this.value.toLowerCase().replace(/\s/g, ''));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
<input type="text" name="full_name" id="full_name" placeholder="Full Name" />
</p>
<p>
<input type="text" name="last_name" id="last_name">
</p>
$('#full_name').keyup(function(){
$val = $(this).val()
stripped_val = $val.replace(' ', '');
lowercase_stripped_val = stripped_val.toLowerCase();
$('#last_name').val(lowercase_stripped_val);
});
Or, in short:
$('#full_name').keyup(function(){
$val = $(this).val()
modified_val = $val.replace(' ', '').toLowerCase();
$('#last_name').val(modified_val);
});