473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to change a picture using radio button

Expand|Select|Wrap|Line Numbers
  1. <img src="1.jpg">
  2. <input type="radio" name="r1" value="one">
  3.  
  4. <img src="2.jpg">
  5. <input type="radio" name="r1" value="two">
  6.  
  7. <div>
  8. <img src="">
  9. </div>
i want the picture to be changed in side the <div> to the specific image
if i click "one" radio button, 1.jpg should be displayed like wise if i click "two" radio button, 2.jpg should be displayed..

how can i do this?
Mar 13 '15 #1

✓ answered by Exequiel

but you can also change the image result without using radio button, you can directly use the images to view it in a big mode.
try this.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Zick Sample</title>
  6. <style>
  7. img{
  8.     border:8px solid rgba(255,255,255,0.8);
  9.     box-shadow:1px 1px 1px 1px rgba(1,1,1,0.3);
  10.     margin:5px;
  11.     cursor:pointer;
  12.     }
  13. .img{
  14.     width:300px;
  15. }
  16. .bigimg{
  17.     width:700px;
  18. }
  19. </style>
  20. <script>
  21.  
  22. function imagechanger(myvalue)
  23. {
  24.     var resultimg = document.getElementById("resultimage");
  25.     resultimg.innerHTML = "";//empty the resultimage div element
  26.  
  27.     var imge = document.createElement("IMG");//create new element image
  28.     imge.setAttribute("src", myvalue);//setting of its attribute src and class
  29.     imge.setAttribute("class", "bigimg");
  30.     resultimg.appendChild(imge);//put the newly created image in resulimage div element id
  31. }
  32. </script>
  33. </head>
  34. <body>
  35.  
  36. <img src="http://i1.2pcdn.com/node14/image/game/50da9450c01d0e168514075c/50e13d0061fc7025162e958c/20121231022213a0dczsyrom2zmu9j.jpg" class="img" onclick="imagechanger(this.getAttribute('src'))">
  37. <img src="http://i.ytimg.com/vi/IEtuDtJHTkg/maxresdefault.jpg" class="img" onclick="imagechanger(this.getAttribute('src'))">
  38. <br>
  39. <div id="resultimage"><!--result of image here--></div>
  40.  
  41. </body>
  42. </html>

5 1541
Dormilich
8,658 Expert Mod 8TB
you set an event to the checkboxes and from this event you toggle the image display.
Mar 13 '15 #2
Exequiel
288 256MB
Try this code. its a simple coding here.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Zick Sample</title>
  6. <style>
  7. img{
  8.     border:8px solid rgba(255,255,255,0.8);
  9.     box-shadow:1px 1px 1px 1px rgba(1,1,1,0.3);
  10.     margin:5px;
  11.     }
  12. .img{
  13.     width:300px;
  14. }
  15. .bigimg{
  16.     width:700px;
  17. }
  18. </style>
  19. <script>
  20.  
  21. function imagechanger(myvalue)
  22. {
  23.     var resultimg = document.getElementById("resultimage");
  24.     resultimg.innerHTML = "";//empty the resultimage div element
  25.  
  26.     var imge = document.createElement("IMG");//create new element image
  27.     imge.setAttribute("src", myvalue);//setting of its attribute src and class
  28.     imge.setAttribute("class", "bigimg");
  29.     resultimg.appendChild(imge);//put the newly created image in resulimage div element id
  30. }
  31. </script>
  32. </head>
  33. <body>
  34.  
  35. <img src="http://i1.2pcdn.com/node14/image/game/50da9450c01d0e168514075c/50e13d0061fc7025162e958c/20121231022213a0dczsyrom2zmu9j.jpg" class="img">
  36. <input type="radio" name="r1" value="http://i1.2pcdn.com/node14/image/game/50da9450c01d0e168514075c/50e13d0061fc7025162e958c/20121231022213a0dczsyrom2zmu9j.jpg" onchange="imagechanger(this.value)">
  37.  
  38. <img src="http://i.ytimg.com/vi/IEtuDtJHTkg/maxresdefault.jpg" class="img">
  39. <input type="radio" name="r1" value="http://i.ytimg.com/vi/IEtuDtJHTkg/maxresdefault.jpg" onchange="imagechanger(this.value)">
  40. <br>
  41. <div id="resultimage"><!--result of image here--></div>
  42.  
  43. </body>
  44. </html>
Mar 13 '15 #3
Exequiel
288 256MB
but you can also change the image result without using radio button, you can directly use the images to view it in a big mode.
try this.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Zick Sample</title>
  6. <style>
  7. img{
  8.     border:8px solid rgba(255,255,255,0.8);
  9.     box-shadow:1px 1px 1px 1px rgba(1,1,1,0.3);
  10.     margin:5px;
  11.     cursor:pointer;
  12.     }
  13. .img{
  14.     width:300px;
  15. }
  16. .bigimg{
  17.     width:700px;
  18. }
  19. </style>
  20. <script>
  21.  
  22. function imagechanger(myvalue)
  23. {
  24.     var resultimg = document.getElementById("resultimage");
  25.     resultimg.innerHTML = "";//empty the resultimage div element
  26.  
  27.     var imge = document.createElement("IMG");//create new element image
  28.     imge.setAttribute("src", myvalue);//setting of its attribute src and class
  29.     imge.setAttribute("class", "bigimg");
  30.     resultimg.appendChild(imge);//put the newly created image in resulimage div element id
  31. }
  32. </script>
  33. </head>
  34. <body>
  35.  
  36. <img src="http://i1.2pcdn.com/node14/image/game/50da9450c01d0e168514075c/50e13d0061fc7025162e958c/20121231022213a0dczsyrom2zmu9j.jpg" class="img" onclick="imagechanger(this.getAttribute('src'))">
  37. <img src="http://i.ytimg.com/vi/IEtuDtJHTkg/maxresdefault.jpg" class="img" onclick="imagechanger(this.getAttribute('src'))">
  38. <br>
  39. <div id="resultimage"><!--result of image here--></div>
  40.  
  41. </body>
  42. </html>
Mar 13 '15 #4
thank you sir for helipng with this
Mar 14 '15 #5
Exequiel
288 256MB
no problem. just enhance the code. :)
Mar 14 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Don Grover | last post by:
I have a table thats wrapped in a div tag, that when user selects 1 of 2 radio buttons it hides or shows table, this works ok. But I want to set the table show hide on what the existing state of...
1
by: KatB | last post by:
I'm creating an asp.net page using VS.NET. TOPIC1 Radio button list TOPIC2 Radio button list etc.
2
by: Bob Alston | last post by:
I have an application with several forms. Most forms use radio boxes for Yes/No choices. On a few of these, once one option is selected, the user cannot change the selection without moving to...
1
by: shror | last post by:
Hi every body, i want to know how i can use two radio buttons to turn on/off a midi file on my webpage, so that if the midi is running and i choose the off radio button then the midi is switched...
3
by: Milsnips | last post by:
hi there, i have a repeater which returns me a list of addresses in each repeaterItem row. at the end of each row i have a radiobutton, which i want the user to select the "active" address. ...
2
by: cloh | last post by:
Hi all, Does anyone know if it is possible to change the color of a radio button in a form? Changing either the color of the border or the dot would work for me - I just need it to stand out from...
1
by: hellogohel | last post by:
hi all, how do i display in detailview that is selected from gridview radiobutton? coding dynamically thanks in advance
2
by: dangerouskicker | last post by:
dear friends any one can guide me or help, How i can change checkbox and radio button color change with java script regards devang
1
by: rjlorenzo | last post by:
Good Day, I just need help on my programming. I would like to try to retrieved/edit the data i've save using radio button and want it to displayed on radio button for editing or changing the...
1
by: imtiyazrdl | last post by:
Hi I need customer can select delivery day name (Saturday and thus day ) using radio button and radio button is value store in order table or any new table and also mansion this day value in order...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.