Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,284 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,022 people online right now. Registration is fast and FREE... Join Now!




checkbox display help

 
Reply to this topicStart new topic

checkbox display help

rmw
27 Dec, 2008 - 02:16 PM
Post #1

New D.I.C Head
*

Joined: 29 Nov, 2008
Posts: 32

Hi,

I am trying to read the selected contents on my form and then output them to a textbox. It will only display the last item and not both of them ..heelp

Any tips much appreicated smile.gif

CODE


<html>
<head>
<title>itmes</title>
<script language="JavaScript" type="text/javascript">


function esa() {
var checkboxes = document.forms["appform"].appliance.length;
for (var i = 0; i < checkboxes; i++) {
if (document.forms["appform"].appliance[i].checked) {
var selection = document.forms["appform"].appliance[i].value;
document.getElementById( "Results" ).innerHTML = selection;
}
    }
        }
    
</script>

</head>

<body>

<form id= "appform" action="#" onsubmit="return false;" >
<p> Selection : </P>

<input type="checkbox" id="1" value="keyboard" name="appliance" /> licence<br/>

<input type="checkbox" id="1" value="mouse" name="appliance" /> config<br/>

<p><input TYPE="submit" id="formsubmit" name="formsubmit" VALUE="Summary" onClick="esa();"></p>

<p>
<textarea id= "Results">
</textarea>
</p>

</form>
</body>
</html>



User is offlineProfile CardPM
+Quote Post


BetaWar
RE: Checkbox Display Help
27 Dec, 2008 - 08:28 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 3,812



Thanked: 203 times
Dream Kudos: 1325
My Contributions
textareas can use the value attribute.

The problem you were having with that you weren't adding to the value, you were overwriting it each time through the loop.

CODE
<script language="JavaScript" type="text/javascript">
function esa(){
  var checkboxes = document.forms["appform"].appliance.length;
  document.getElementById("Results").value = "";
  for(var i = 0; i < checkboxes; i++){
    if(document.forms["appform"].appliance[i].checked){
      var selection = document.forms["appform"].appliance[i].value;
      document.getElementById("Results").value += selection+"\n";
    }
  }
}    
</script>


Hope that helps.
User is online!Profile CardPM
+Quote Post

rmw
RE: Checkbox Display Help
29 Dec, 2008 - 12:18 PM
Post #3

New D.I.C Head
*

Joined: 29 Nov, 2008
Posts: 32

*Resolved* - Your're a legend icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:59PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month