Change Javascript variable image source based on radio button selection



<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
 
 
 
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">
 
  <style type="text/css">
   
  </style>
 



<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('.radio').on({
    'click': function(){
        console.log($(this).val());
        var image_url=$(this).val();
        $('#my_image').attr('src',image_url);
    }
});
});//]]>

</script>

</head>
<body>
   <img id="my_image" src="http://i.imgur.com/tL6nW.gif" alt="">

     <br>
<input class="radio" name="radio" value="http://i.imgur.com/tL6nW.gif" checked="" type="radio">Image1<br>
   
<input class="radio" name="radio" value="http://i.imgur.com/BfZ5f.gif" type="radio">image2

 




</body></html>

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Real-Time Web Interface to MQTT using Socket.io and Node.js

Customize radio buttons and checkboxes with CSS sprites