jquery - How to Swap the options of two select Boxes -
i have 2 select boxes below.
<form name="test"> <select id="s1" name="select1"> <option selected>1</option> <option>2</option> <option>3</option> </select> <select id="s2" name="select2"> <option>1</option> <option>2</option> <option selectd>3</option> </select> <input type="button" value="swap" id="swap"> </form>
"1" selected in select box 1 , "3" selected in select box 2.
now clicking button 2 value should swap. means "3" in select box 1 , "1" in select box 2.
i have tried jquery that. code below.
$("#swap").click(function(){ v1=document.getelementbyid("s1"); v2=document.getelementbyid("s2"); document.form.select1.value=v2; document.form.select2.value=v1; });
but didnt result. whats wrong doing.??
thanks in advance,
shoba.
$('#swap').click(function(){ var v1 = $('#s1').val(), v2 = $('#s2').val(); $('#s1').val(v2); $('#s2').val(v1); });
Comments
Post a Comment