Reputation: 2824
I have the following 2 fields in my large form...
<p><input type="text" name="name" id="proname" value="" /></p>
<p><input type="text" name="var" id="provarname" value="" /></p>
I want #provarname to get the value live automatically from #proname, for example if we enter Design watch in #provarname, same time #provarname should get value design-watch(small letters and space replaced with -) , and i have written following jquery code which is not working in same manner...
$(document).ready(function() {
$('#proname').live('change',function() {
var pronameval = $(this).val();
$('#provarname').val(pronameval.replace(' ', '-'));
});
});
Upvotes: 0
Views: 1357
Reputation: 1955
Add toLowerCase if you want it all in lowercase
var pronameval = $(this).val().toLowerCase();
And use keyup as been said already
Upvotes: 0
Reputation: 79850
g
so it does replace all. keyup
instead of change
, change
will be triggered onblur
of the textbox.Change your function as below,
DEMO here
$('#proname').live('keyup',function() {
var pronameval = $(this).val();
$('#provarname').val(pronameval.replace(/ /g, '-').toLowerCase());
});
Upvotes: 0
Reputation: 2824
As per suggestion by T.stone, the final code would be...
$(document).ready(function() {
$('#proname').live('keyup',function() {
var pronameval = $(this).val();
$('#provarname').val(pronameval.replace(' ', '-').toLowerCase());
});
});
which is working fine.
Upvotes: 0