Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

getting checkbox value in Javascript

Hi all,

I am trying to check the value of the checkbox( true or false) in javascript in page layout by

if (formid.checkboxid.checked == "TRUE" )..

But it is not working ? giving syntax error in JavaScript.. What is the right syntax ? Thanks in advance.

Regards,

Ananya

Former Member
Former Member replied

Hi Ananya,

Here is a sample code.

<html>
<head>
<script language=javascript>
function validate(chk1,chk2,chk3,chk4){
  if (chk1.checked == 1)
    alert("You have selected Red");
  if (chk2.checked == 1)
    alert("You have selected Orange");
  if (chk3.checked == 1)
    alert("You have selected Blue");
  if (chk4.checked == 1)
    alert("You have selected Pink");
  if(chk1.checked == 0 && chk2.checked == 0 && chk3.checked == 0 && chk4.checked == 0)
  {
    alert("You didn't check any thing! Let me check it for you.")
    chk1.checked = 1; 
  }
}
</script>
</head>
<body>
<form>
What's is your favourite color?
<br>
<input type=checkbox name=chk1>Red
<br>
<input type=checkbox name=chk2>Orange
<br>
<input type=checkbox name=chk3>Blue
<br>
<input type=checkbox name=chk4>Pink
<br>
<p><input type=button value="Submit" onclick="return validate(chk1,chk2,chk3,chk4);">
</form>
</body>
</html>

Hope it solves your problem.

Regards,

Maheswaran.B

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question