Multiple Choice Checkbox Value \alert\"

  • 20 December 2018
  • 7 replies
  • 7 views

Badge +3

Why am I not getting the values of multiple selected check boxes with this code? what would rather work? Open to all suggestions. Thank you!

NWF$('#' + varMultiChoice).click(function(){
alert(NWF$('#' + varMultiChoice).val());
});‍‍‍

7 replies

Badge +7

It's because the values aren't actually in the varMultiChoice field. It's a table. The values you're looking for are in the input fields inside the table.

Try this:

NWF$('#' + varMultiChoice + ' input').click(function(){
    alert(NWF$(this).val());
});
Badge +3

I am not getting the value though. It just says "on" and I know it is because that's how it has been default coded.

what I am trying to do is to get the value (name) of the selected checkbox. In this case it should be "High Pressure".

This is why I am getting value "on". Is there any way to get data-nfChoiceValue?

MultiChoice

This is what I am getting.

alert

Badge +7

When I tested a Choice field with checkboxes, it set the text as the value of the input field as well as being the text of the label:

221727_pastedImage_2.png

221726_pastedImage_1.png

I suppose you could try something like this, where it grabs the text of the label that is immediately after the input field:

NWF$('#' + varMultiChoice + ' input').click(function(){
     alert(NWF$(this).next("label").text());
});
Badge +3

Thank you so much Chad Davis. It worked. happy.png 

Badge +3

Thank you Chad Davis, it was a very big help but I am still kind of stuck because I am not able to mark the value as selected which was the main purpose of this alert. I was testing it. Any idea how can I select one specific option with JS. I really appreciate your help. 

What I am try to do Rule 1

If user clicks "Not Applicable" all other options should go hide.

If user clicks any other option "Option 1" or "Option 2" then "Not Applicable" should go hide and I want to keep them all in one control.

Rule 2

If user change a lookup field in my form all other controls: textbox and dropdown are getting values automatically (because they are text fields) based on item selected from sharepoint list but this control (MultiChoice) is just getting the value but it is not populating i.e. It is not marking it as selected option which I may need to do with code manually like - if else. For this reason I am trying to understand how can I mark the option as selected, even by referring to label doesn't matter. Please feel free to share your thoughts. Thank you!

Badge +7

Can you include some print screens of what you're trying to accomplish? I'm more of a visual learner.

Badge +3

Here let me take you to the right direction. I have this question but so far I don't have any reply. In this post we are not discussing Rule 1. It is all about Rule 2 what I explain here.

  

Reply