Link to home
Start Free TrialLog in
Avatar of Jordan Johnson
Jordan Johnson

asked on

How can I retrieve the value of this checkbox in Javascript?

I am trying to retrieve the value, of whether the checkbox is checked or not, but it is not working. When I retrieved the value it just says "on" whether or not it is checked. Can someone help point me in the right direction? Thanks!

<script language="javascript">
function checkForm()
{
  
  emailcheckcount = 0;
  for(i=0; i<=numrows; i++)
  {
	  var recid = document.forms["theform"]["recid"+i].value;
	  
	  
    if(document.theform.recid+"_to"+i.checked) {
        emailcheckcount++;
    }
  
    if(emailcheckcount == 0) {
    alert("Please Select At Least One Email for Alerts");
	return false;
    }
  
  document.theform.submit();
}
</script>

<input type='checkbox' name='<%=recid%>_to<%=emailnum%>'>

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>><input type='checkbox' name='<%=recid%>_to<%=emailnum%>'>
may we know what's the output generated from this?

>>for(i=0; i<=numrows; i++)
did you save the value of numrows in your Javascript as well?

I believe this is not the full scripts to generate the output page?
Avatar of Jordan Johnson
Jordan Johnson

ASKER

I took out some of the code, sorry. It does get the numrows

numrows = document.theform.numrows.value;

Open in new window


The output looks like this for the checkbox name ie - "19181_to0"
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial