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

PHP Ajax Login Validation Tutorial

Insert CheckBox and Radio button Data in MySQL Database Using PHP