Solved

fancy checkboxes or other toggle-switches

Posted on 2003-10-22
6
350 Views
Last Modified: 2006-11-17
Hi,

is it possible to use javascript (or any other web-development language to make a web-page that contains a toggle switch that changes color upon being pressed.

for example,  press once on a square and the square goes from white to black.  press again and it goes from black to white.  etc. etc.

basically, it behaves like a checkbox, but maybe is easier to see visually.

Thanks for any help!
0
Comment
Question by:pdanese
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
Xxavier earned 38 total points
ID: 9604599
Try this

<script>
col="cRed"
function swap(){
 if (col=="cRed")
     {col="cBlue"
     return "#0000FF"}
 else
    {
     col="cRed"
     return "#FF0000"}
}
</script>
<table bgColor="red" width="30" onclick='this.bgColor = swap()'>
<tr><td>&nbsp;&nbsp;</td></tr>
</table>

0
 
LVL 3

Expert Comment

by:alexgreen
ID: 9605071
pdanese

are you wanting it to be available for submitting a form (don't think it's possible) or just as an aesthetic thing (Which X's code wil provide without any problem)

0
 
LVL 18

Assisted Solution

by:Plucka
Plucka earned 37 total points
ID: 9605377
You can do it easily. I'm not going to write it for you, but i've seen it before.

1. Create your tick box as an image.
2. Have an onclick event that toggles the image between the two states. This will also need to set the value of a hidden form variable.
3. Do normal form processing as the hidden form variables will contian you results.

Hope this helps.

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 7

Expert Comment

by:Xxavier
ID: 9610421
Oh dear I was coding late last night and the code I gave you looks terrible, this is better


<table bgColor="#FF0000" width="30" onclick="(/ff0000/.test(bgColor))?bgColor='blue':bgColor='red'">
  <tr>
    <td>&nbsp;&nbsp;</td>
  </tr>
</table>


Alex surely you can add formName.submit() to the onclick

Xx
0
 
LVL 3

Expert Comment

by:alexgreen
ID: 9610639
yep, not thinking straight! soz
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9611527
looking at the code I submitted late last night neither was I. :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question