473,395 Members | 1,762 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,395 software developers and data experts.

Using images as radio buttons

Hi all
Complete newbie. Have a table posing the question "Which do you like best"? Two possible responses. Want to replace radio buttons COMLETELY with images that represent those possible responses. With A LOT of help, I've done that using a "hidden" question (code below). It works - I've checked and clicking on one or other image indeed returns the corresponding value. As far as the user is concerned, however, nothing is happening. Not ideal.

I have two images for each choice - the originals that come up on page load, and a version of each with a big tick in the middle, which I would LIKE to come up onclick. Can anyone enlighten me on how to make it so that if CokeRange.jpg is clicked, CokeRangeClicked.jpg shows and if PepsiRange.jpg is clicked, PepsiRangeClicked.jpg shows - but that, like the radio buttons they are pretending to be, only one of the images remain with the big tick?

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. <input id="Q6_var" name="Q6_var" type="hidden" value="0">
  2.  
  3. <TABLE CELLPADDING="5" BORDER="0" width="100%">
  4.    <TR>
  5.      <TD>
  6.     <img src="[%GraphicsPath()%]CokeRange.jpg" alt="" border="1"
  7.     onclick="Q6_var.value=1;">
  8.     </TD>
  9.      <TD>
  10.       <img src="[%GraphicsPath()%]PepsiRange.jpg" alt="" border="1"
  11.     onclick="Q6_var.value=2;">
  12.     </TD>
  13.   </TR>
  14. </TABLE>
Feb 17 '08 #1
3 2449
hsriat
1,654 Expert 1GB
[html]
<script type="text/javascript">
function changeVal(value) {
document.getElementById('Q6_var').value = value;
var coke = document.getElementById('im1');
var pepsi = document.getElementById('im2');
coke.src = value==1 ? 'cokeRangeClicked.jpg' : 'cokeRange.jpg' ;
pepsi.src = value==1 ? 'pepsiRange.jpg' : 'pepsiRangeClicked.jpg' ;
}
</script>
<input id="Q6_var" name="Q6_var" type="hidden" value="0">

<TABLE CELLPADDING="5" BORDER="0" width="100%">
<TR>
<TD>
<img id="im1" src="CokeRange.jpg" alt="" border="1"
onclick="changeVal(1);">
</TD>
<TD>
<img id="im2" src="PepsiRange.jpg" alt="" border="1"
onclick="changeVal(2);">
</TD>
</TR>
</TABLE>
[/html]
Feb 17 '08 #2
Thank you very much!! I've checked the data, and the correct value is being set for the image chosen. A thing of beauty.
Feb 17 '08 #3
hsriat
1,654 Expert 1GB
Thank you very much!! I've checked the data, and the correct value is being set for the image chosen. A thing of beauty.
You are welcome. :)

But in future, do ask such questions in Javascript Forum. You may get more replies there.
Feb 18 '08 #4

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

Similar topics

2
by: Newbie | last post by:
I currently have a set of simple calculations to determine square footage and multuply that by a dollar amount per foot. I use form fields that are filled in by the user, and then the Submit...
4
by: Ken Fine | last post by:
I've made a content managment system that uses icons to represent page layouts. To choose a different layout, the user clicks on a radio button associated with each layout icon. On click of one of...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
5
by: Axel | last post by:
An Access 2000 question Hi is is possible to have (as a subform) a continous form with 0..n buttons which have different images in each row. (Personally I would have preferred a button...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
76
by: rcoco | last post by:
Hi all, I'm facing this problem I have images on my website but when I Deploye the website on server the Images are not there I only get the X sign. How can I go about this. Thanks
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.