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.



Former Member
Former Member replied

Hi Ananya,

Here is a sample code.

<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; 
What's is your favourite color?
<input type=checkbox name=chk1>Red
<input type=checkbox name=chk2>Orange
<input type=checkbox name=chk3>Blue
<input type=checkbox name=chk4>Pink
<p><input type=button value="Submit" onclick="return validate(chk1,chk2,chk3,chk4);">

Hope it solves your problem.



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