Solved

get checkbox value with javascript

  • 10 November 2015
  • 5 replies
  • 572 views

Badge +2

Does anyone know how you get the value of a checkbox with javascript?  I have a checkbox with one value called override and the field value is stored in the variable varGROR

I tried these and others but none work:

 

 

 

 

NWF$('#' + varGROR).val();

 

NWF$('#' + varGROR + ' option:selected');

 

Can anyone help?

icon

Best answer by mlauer 10 November 2015, 17:46

View original

5 replies

Badge +9

To get value of checkbox try

 

NWF$('#' + varGROR).prop('checked')

 

It will return 'true' or 'false'.

Badge +2

Thanks.  That works if I change my field from a choice field  checkbox with 1 option to a yes no checkbox with one option.

I don't suppose you also know how to get the value of a choice field with option or check boxes where there are multiple options, as I keep getting 'undefined'

Badge +9

Hi Liz,

A multichoice control will store the entries as an Array. The following code can execute on  a mult Choice control with a JavaScript Variable named 'multiChoices'. The log entry occurs on a button click calling the showMe() function.

  1. function showMe() {
  2.   var c = [];
  3.   NWF$('#' + multiChoices + ' :checkbox:checked').each(function(i) {
  4.    c[i] = NWF$(this).val();
  5.    console.log(c[i]);
  6.   });
  7. }

Thank you,

Sean Fiene

Badge +2

Thanks Sean. I'll give that a go

Badge +2

Hey @sean_fiene,


How did you store this to a variable so that I can call it from a different list?

Reply