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

how to dynamically manipulate icons using javascript

Folks,

I need a working code to do the following or something similar.

I have two icons in the screen. One to indicate right (a tick mark) and
one to indicate wrong (a cross).

If the user clicks on the first icon it should become tick and the
second one should become cross.

If the user clicks on the second icon then it should become tick and
the first one should become cross.

all this must happen in client side (no post back).

This is not my actual requirement but a small part of it. Once I have a
prototype code to do this I will build the rest from there.

Thanks

Dec 1 '06 #1
1 1409
ASM
ja************@yahoo.com a écrit :
Folks,

I need a working code to do the following or something similar.

I have two icons in the screen. One to indicate right (a tick mark) and
one to indicate wrong (a cross).
click what icon you want exchanges both images

<img src="ok.jpg" alt="" name="ok"
onclick="
var icon = this.src;
this.src = document.KO.src;
document.KO.src = icon;
">
<img src="X.jpg" alt="" name="KO"
onclick="
var icon = this.src;
this.src = document.ok.src;
document.ok.src = icon;
">
I would prefer :

one image (icons.jpg) with both icons

+-----+-----+
| | |
| O K | X |
| | |
+-----+-----+

CSS :
=====

..icon { cursor: pointer; }
..icon span { background: url(icons.jpg) no-repeat left center; }
..icon span.ko { background-position: right center; }

JS :
=====

function icon(what) {
what = what.getElementsByTagName('SPAN')[0];
what.className = what.className==''? 'ko' : '';
}

HTML :
======

<p class="icon" onclik="icon(this);">
<span>&nbsp; &nbsp;</span>Question 1</p>
<p class="icon" onclik="icon(this);">
<span>&nbsp; &nbsp;</span>Question 2</p>
<p class="icon" onclik="icon(this);">
<span>&nbsp; &nbsp;</span>Question 3</p>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I...
1
by: antishok | last post by:
Hi, I'm writing a page which has a somewhat similar folder tree to that of the windows explorer, where each folder is made of a <SPAN> tag consisting of the folder image (closed or open) and the...
6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
2
by: obsidian8 | last post by:
Hi All, I have looked around for an answer to this question, but haven't found one as of yet. I'm trying to use javascript to dynamically create raido buttons. I am able to create them easily...
2
by: James Black | last post by:
I am dynamically generating a table in IE to display some information. I will probably change it to divs later, but I just want to get it working properly first. In my div I have the following...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
0
by: archcommus | last post by:
Hey all, First post on thescripts, this site has answered many of my questions in the past via searching. Basically, my philosophy on the taskbar and notification area is that what's displayed...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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...
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,...

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.