jquery - Javascript - Swap input element on click -
saw on xe.com swap currency on form. need site also. not question, solve problem , sharing here:
html
<form target=""> <input name="input1" id="firstinput" value="input #1"> <input name="input2" id="secondinput" value="input 2"> </form> <a class="swap">swap</a>
javascript
$(document).ready(function () { $("a.swap").click(function(){ var axix = document.getelementbyid("firstinput").value; var byiy = document.getelementbyid("secondinput").value; document.getelementbyid('secondinput').value = axix; document.getelementbyid('firstinput').value = byiy; }); });
demo: http://jsfiddle.net/z5vse/
any better way it? share us. :)
shorter (not "better"):
$("a.swap").click(function () { $('#pickup').val([$('#destination').val(), $('#destination').val($('#pickup').val())][0]) });
imo "better" mean clean, clear, , concise.
$("a.swap").click(function () { var temp = $('#pickup').val(); $('#pickup').val($('#destination').val()) $('#destination').val(temp); });
Comments
Post a Comment