Andrew Allen West Andrew Allen West - 5 months ago 9
jQuery Question

On losing focus - input not auto-filling

So I have a multi-part form that is supposed to auto fill another input. I have used blur to recognize when the input has lost focus, but I cannot get it to auto fill the other input with the value of the input losing focus. What I have looks pretty simple and logical to me, simply is not working.

Any help is appreciated.

company_name.blur(function(){
$('#dba').val(company_name.val());
});


UPDATE

It appears there is something more than what the eye is catching doing this. The easy answer below me should have been right, and I imagine my code is right and something else is doing the dirty work.

I couldn't get the code highlighter to work nicely with my code so I have put it in a text file for you to view.
Thanks again!


http://www.codewithphp.com/form.txt

Answer

What is company_name set to? The following works for me!

HTML

<div>Type something here:<input name="editMe" type="text" /></div>

<div>Populates here:<input name="target" type="text" /></div>

jQuery

$(document).ready(function() {
    $("input[name=editMe]").blur(function() {
        $("input[name=target]").val($(this).val());
    });
});

jsFiddle