javascript - how to set link in dropdown value using onchnage event in html -


please me out issue. here how set different anchor tag in dropdown different value using onchange event in html.

 <form method="post">  <select onchange="$('#imagetoswap').attr('src',this.options[this.selectedindex].value);">   <option value="http://dummy.com/images/button1.png" selected>test1</option>  <option value="http://dummy.com/images/button2.png">test2</option>  </select>   </form>    test1:  <a href="https://link1.com"><img id="imagetoswap" class="class1" src="http://dummy.com/images/button1.png"></a>   test2: <a href="https://link2.com"><img id="imagetoswap" class="class1" src="http://dummy.com/images/button2.png"></a> 

modified code replacing id of image:

<form method="post">  <select onchange="$('#imagetoswap').attr('src',this.options[this.selectedindex].value);">   <option value="http://dummy.com/images/button1.png" selected>test1</option>  <option value="http://dummy.com/images/button2.png">test2</option> 

test1:

 <a href="https://link1.com"><img id="imagetoswap1" class="class1" src="http://dummy.com/images/button1.png"></a> 

test2:

<a href="https://link2.com"><img id="imagetoswap2" class="class1" src="http://dummy.com/images/button2.png"></a> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -