?
Solved

Undefined checkbox

Posted on 2004-09-05
3
Medium Priority
?
1,289 Views
Last Modified: 2012-05-05
The program will return an undefined string when there is only one checkbox. Why and how to fix it?

thanks.
0
Comment
Question by:hawkly
[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 Comments
 
LVL 14

Accepted Solution

by:
ziffgone earned 100 total points
ID: 11986920
Pretty vague question, but try this out:

<script type="text/javascript">
var chkbox= document.form_name.elements['checkbox_name'];
if(chkbox.checked == true){
       var val = document.formname.elements['checkbox_name'].value;
}
else{
       var val = "";
}
alert(val);
</script>

Hope that helps.

Regards...
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 11987020
"The program will return an undefined string when there is only one checkbox, Why and how to fix it?"

Probably because when there is only one checkbox the string variable is not assigned a value. To fix it make sure the variable is assigned a value when there is only one checkbox
0
 
LVL 8

Assisted Solution

by:RozanaZ
RozanaZ earned 100 total points
ID: 11987413
<HTML>
<HEAD>
<TITLE></TITLE>

<script>
function getValue()
{
      checkObj = document.getElementById("ch1");
      alert("Selected: " + checkObj.checked + " value: " + checkObj.value);
}
</script>
</HEAD>
<BODY>
<form>
<input type="checkbox" name="ch1" id="ch1" value="CheckBox 1">CheckBox 1<br>
<input type="button" value="Get Value" onClick="getValue()">
</form>
</BODY>
</HTML>
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

741 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