[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select Image like a radio button; multiple button groups on page.

Posted on 2010-01-02
3
Medium Priority
?
354 Views
Last Modified: 2012-05-08
I have adapted the related solution previously given, but I want to have multiple button groups on the same page. How is this best accomplished?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
     function setSelected(obj) {
          var mySpans = document.getElementById("myImgs").getElementsByTagName("td");
          for (var t=0,spn; spn=mySpans[t]; t++) {
               spn.style.border = "4px white solid";
			   spn.style.background = "#eee";
			   spn.style.color = "black"
          }
          obj.style.border = "4px green solid";
		  obj.style.background = "white";
		  obj.style.color = "green";
          document.getElementById("selectedImg").value = obj.childNodes[0].id;
     }</script>
     
<style>
body {
	font-family:Georgia, "Times New Roman", Times, serif;
	font-size:.8em;
}
table {
	width:50%;
}
td {
	width:150px;
	vertical-align:top;
	padding:12px;
	border:4px white solid;
	text-align: center;
	-moz-border-radius:18px;
	-webkit-border-radius:18px;
}
tr {
	background-color:#eee;
}
</style>
<title>Daily Check-In</title>
</head>
<body>
<table align="center" id="myImgs">
  <form>
    <tr>
      <td colspan="5"><h3>Today, my overall ENERGY is:</h3></td>
    </tr>
    <tr>
      <input type="hidden" id="energy" name="energy">
      <td id="01" onclick="setSelected(this)"><img src="images/batt-01.png"><br />
        Very Low</td>
      <td id="02" onclick="setSelected(this)"><img src="images/batt-02.png"><br />
        Somewhat Low</td>
      <td id="03" onclick="setSelected(this)"><img src="images/batt-03.png"><br />
        Average</td>
      <td id="04" onclick="setSelected(this)"><img src="images/batt-04.png"><br />
        Somewhat High</td>
      <td id="05" onclick="setSelected(this)"><img src="images/batt-05.png"><br />
        Very High</td>
    </tr>
    <tr>
      <td colspan="5"><h3>Today, my overall MOOD is:</h3></td>
    </tr>
    <tr>
      <input type="hidden" id="mood" name="mood">
      <td id="01" onclick="setSelected(this)"><img src="images/mood-01.png"><br />
        Very Sad</td>
      <td id="02" onclick="setSelected(this)"><img src="images/mood-02.png"><br />
        Somewhat Sad</td>
      <td id="03" onclick="setSelected(this)"><img src="images/mood-03.png"><br />
        Average</td>
      <td id="04" onclick="setSelected(this)"><img src="images/mood-04.png"><br />
        Somewhat Happy</td>
      <td id="05" onclick="setSelected(this)"><img src="images/mood-05.png"><br />
        Very Happy</td>
    </tr>
    <tr>
      <td colspan="5"><input name="submit" type="button" value="SUBMIT" /></td>
    </tr>
  </form>
</table>
</body>
</html>

Open in new window

0
Comment
Question by:jsuelflow
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
kadaba earned 1000 total points
ID: 26164410
like this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
     function setSelected(obj,hiddenParamId) {
          var mySpans = obj.parentNode.getElementsByTagName("td");
          for (var t=0,spn; spn=mySpans[t]; t++) {
               spn.style.border = "4px white solid";
			   spn.style.background = "#eee";
			   spn.style.color = "black"
          }
          obj.style.border = "4px green solid";
		  obj.style.background = "white";
		  obj.style.color = "green";
		  document.getElementById(hiddenParamId).value = obj.childNodes[0].id;
     }</script>
     
<style>
body {
        font-family:Georgia, "Times New Roman", Times, serif;
        font-size:.8em;
}
table {
        width:50%;
}
td {
        width:150px;
        vertical-align:top;
        padding:12px;
        border:4px white solid;
        text-align: center;
        -moz-border-radius:18px;
        -webkit-border-radius:18px;
}
tr {
        background-color:#eee;
}
</style>
<title>Daily Check-In</title>
</head>
<body>
<form>
<table align="center" id="myImgs">
    <tr>
      <td colspan="5"><h3>Today, my overall ENERGY is:</h3></td>
    </tr>
    <tr>
      <input type="hidden" id="energy" name="energy">
      <td id="01" onclick="setSelected(this,'energy')"><img src="images/batt-01.png"><br />
        Very Low</td>
      <td id="02" onclick="setSelected(this,'energy')"><img src="images/batt-02.png"><br />
        Somewhat Low</td>
      <td id="03" onclick="setSelected(this,'energy')"><img src="images/batt-03.png"><br />
        Average</td>
      <td id="04" onclick="setSelected(this,'energy')"><img src="images/batt-04.png"><br />
        Somewhat High</td>
      <td id="05" onclick="setSelected(this,'energy')"><img src="images/batt-05.png"><br />
        Very High</td>
    </tr>
    <tr>
      <td colspan="5"><h3>Today, my overall MOOD is:</h3></td>
    </tr>
    <tr>
      <input type="hidden" id="mood" name="mood">
      <td id="01" onclick="setSelected(this,'mood')"><img src="images/mood-01.png"><br />
        Very Sad</td>
      <td id="02" onclick="setSelected(this,'mood')"><img src="images/mood-02.png"><br />
        Somewhat Sad</td>
      <td id="03" onclick="setSelected(this,'mood')"><img src="images/mood-03.png"><br />
        Average</td>
      <td id="04" onclick="setSelected(this,'mood')"><img src="images/mood-04.png"><br />
        Somewhat Happy</td>
      <td id="05" onclick="setSelected(this,'mood','myImgs')"><img src="images/mood-05.png"><br />
        Very Happy</td>
    </tr>
    <tr>
      <td colspan="5"><input name="submit" type="button" value="SUBMIT" /></td>
    </tr>
</table>
</form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:jsuelflow
ID: 31672037
With much gratitude! Thank you for your help on this.

Line 74 seemed to have an extraneous 'myImgs' in the onclick; removal of that did not alter functionality; please advise if there was a reason for its inclusion.

Again, very many thank yous!
0
 
LVL 22

Expert Comment

by:kadaba
ID: 26164518
this,'mood','myImgs' should be this,'mood'

No need to include that, sorry missed my eye .

Thanks for the points and have a great day.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

830 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