javascript - copy value from one field to another -
i have found fiddle (cannot remember source): http://jsfiddle.net/fpsdy/1/ want (copy contents field another)
when copy php page, though, doesn't work:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="includes/jquery/jquery-1.10.2.min.js"></script> </head> <body> <script type="text/javascript"> $('input[type=submit]').click(function(){ $('#elm_14').val($('#elm_6').val()); $('#elm_16').val($('#elm_7').val()); }); </script> <input type="text" class="input-text " value="" size="32" name="user_data[firstname]" id="elm_6"> <input type="text" class="input-text " value="" size="32" name="user_data[lastname]" id="elm_7"><br /> <input type="submit" value="continue" name="dispatch[checkout.update_steps]"><br /> <input type="text" class="input-text " value="" size="32" name="user_data[b_firstname]" id="elm_14"> <input type="text" class="input-text " value="" size="32" name="user_data[s_firstname]" id="elm_16"> </body> </html>
i sure have made amateur mistake but, since not know javascript cannot pinpoint it. appreciated
your js code attaches click handler needs run after page loads:
$(function() { // run after dom loaded $('input[type=submit]').click(function(){ $('#elm_14').val($('#elm_6').val()); $('#elm_16').val($('#elm_7').val()); }); });
in code, when js run, submit button doesn't exist yet on page, jquery can't attach click handler.
Comments
Post a Comment