School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

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




checkbox display help

 

checkbox display help

rmw

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

New D.I.C Head
*

Joined: 29 Nov, 2008
Posts: 33

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: 4,728



Thanked: 268 times
Dream Kudos: 1400
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 offlineProfile 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: 33

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

Fast ReplyReply to this topicStart new topic

Time is now: 11/6/09 04:53PM

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