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

x
?
Solved

checkbox values in javascript?

Posted on 2006-06-06
4
Medium Priority
?
196 Views
Last Modified: 2009-12-16
experts,

How can I get checkbox values in Javascript?

function passit()
{

myhazard = document.all.hazard.checked;<--------??????
alert(myhazard);
theResult = myhazard

window.returnValue = theResult
close();
}
0
Comment
Question by:suran78
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:third
ID: 16847943

myhazard = document.formname.hazard.value;

if you want to get the value for checked checkbox,

myhazard = document.formname.hazard.checked?document.formname.hazard.value:'';
0
 
LVL 30

Accepted Solution

by:
third earned 1000 total points
ID: 16847964
here's an example,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Author: Third Santor</title>
<script>
  function getCheckboxValues(obj){
    for(var i=0; i<obj.length; i++){
        if((obj.elements[i].type == 'checkbox') && (obj.elements[i].checked)){
          alert(obj.elements[i].value);
        }
      }
  }
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="" onsubmit="">
<input type="checkbox" name="chk1" value="value1">
<input type="checkbox" name="chk1" value="value2">
<input type="checkbox" name="chk1" value="value3">
<input type="button" value="Click" onclick="getCheckboxValues(this.form);">
</form>
</body>
</html>
0
 

Author Comment

by:suran78
ID: 16848050
Thanks this is working.

i have another open question at http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21877097.html
0
 

Author Comment

by:suran78
ID: 16848072
another small question:

How can I index a row in Javascript?

hazard[rowid].innertext = values  <-------------??????


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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

831 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