Copycat

$(document).ready(function(){ copycat.copyinit("keyup","#l-input-1","#r-input-1"); copycat.copy("change","#l-input-2","#r-input-2"); copycat.copy("change","#l-input-3","#r-input-3"); }); copycat = { copyinit: function(method,input,output) { var jinput = $(input); var joutput = $(output); jinput.on(method,function(){ if(jinput.attr("type") === "checkbox"){ jinput.is(':checked') ? jinput.val("Y") : jinput.val("N"); } joutput.val(jinput.val());}); joutput.val(jinput.val()); }, copy: function(method,input,output) { var jinput = $(input); var joutput = $(output); jinput.on(method,function(){ if(jinput.attr("type") === "checkbox"){ jinput.is(':checked') ? jinput.val("Y") : jinput.val("N"); } joutput.val(jinput.val());}); } }; //Example of HTML markup for code above /* <div class="container-fluid"> <div class="row"> <div class="col-sm-6"> <h1>Input</h1> <form id="first"> <input type="text" name="one" id="l-input-1" class="form-control" value="1111" /> <select class="form-control" id="l-input-2" name="two"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <input type="checkbox" id="l-input-3" class="form-control" name="three" value> </form> </div> <div class="col-sm-6"> <h1>Output</h1> <form id="second"> <input type="text" name="one" id="r-input-1" class="form-control" value="" /> <input type="text" name="two" id="r-input-2" class="form-control" value="" /> <input type="text" name="three" id="r-input-3" class="form-control" value="" /> </form> </div> </div> <div class="clearfix"></div> <hr> <div class="row"> <div class="col-sm-12"> <h2 class="text-center">Log</h2> <pre id="log"></pre> </div> </div> </div> */
This function copying values from one input field to another.
You need to specify method, input field and output field.
After that calling a function.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.