Checkboxes

hi,

How do i define a value of the checkbox. FOr example if a check box is checked then the value should be 'Yes' else 'No'

Thanks Aseem
aseem072898Asked:
Who is Participating?
 
SuperMarioConnect With a Mentor Commented:
Use the javascript that was provided in martinag's comment. In the textarea where you want the answer to be displayed, use this:

-script-
if(checkbox.checked)
{
document.write('Yes')
}

or something like that.


0
 
jedimikeCommented:
you put a "checked" inside
<input type=....    checked>

that's all...dont forget to set the value too.
0
 
martinagCommented:
 <FORM ACTION="script.cgi">
  <INPUT TYPE="CHECK" NAME="chk1" VALUE="Yes">Check it!
  </FORM>
sends "chk=Yes" to the CGI script if it is checked. If it's unchecked, nothing's sent.

Hmmm...maybe that's not what you meant...Is this?
<SCRIPT LANGUAGE="JavaScript">
<!--
function getString(checkbox) {
  return (checkbox.checked) ? "Yes" : "No";
}
alert(getString(document.aForm.aCheckbox)); // Display either "Yes" or "No".
// -->
</SCRIPT>

Please explain if this doesn't help.

Martin
0
 
aseem072898Author Commented:
Sorry,

Neither of you guys understood what i ment. I am making a Javascript in which 'yes' or 'no' is printed  in a textarea. If the guy checks the checkbox then 'yes' is printed or else 'no' is printed.

Thanks
Aseem
0
 
martinagCommented:
<INPUT ... onClick="this.form.thatTextBox.value=((this.checked)?'Yes':'No')">

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.