How do I give a checkbox a separate value and label?


#21

This is a pretty good workaround, except my labels have spaces (since they are labels, after all). To find the element by ID with spaces, you need to use an attribute selector:

$("input[id='mycheckbox_Yes, choose this one']").val("YES");

Not great, but gets the job done.

Thanks for the idea!


#22

Wowza, @Rob! Great solution.


#23

Hi Sean,

This is a good addition thanks!

FYI if your field option labels have spaces those will translate into underscores when referring to the ID in the html markup for the page. So in your example you could use: $("#mycheckbox_yes_choose_this_one").val(“Yes”); as well.

Although it equates to the exact same thing in the end. Six of one, half dozen of the other as they say :slight_smile:


#24

@Rob

I would like to convert a dropdown Yes/No field to Yes=True and No=False in order to integrate with a Salesforce Boolean field. The field ID for the dropdown field is ‘text’. I placed two snips of JS within Unbounce before the body end tag:

<script>
  // ID of option field (field label + option label separated by an underscore)
  $("#text_yes").val("True"); // Add value 
</script>

and

<script>
  // ID of option field (field label + option label separated by an underscore)
  $("#text_no").val("False"); // Add value 
</script>

After testing, I am still seeing the following integration error:
Request Error: Salesforce received Yes or request may be missing a required field which should be sent as a boolean field. Please update your field mapping configuration.

Any thoughts on what I might be overlooking here? Thanks!


#25

Hi @Hayley_Warack could you share a link to the page (feel free to PM me if you don’t want to share it here). The code you pasted looks ok to me assuming your dropdown field has an ID of “text”. I’ll be able to let you know for sure though once I have a look at the page :slight_smile:

The above code won’t change the field value to a boolean though unfortunately. It will still be a string that says either true or false, which is still a bit different than a boolean value I’m afraid. Unbounce sends everything as a string.

Hope this helps a bit! Send along the page though and I can have a closer look for ya!


#26

Hi @Rob -

Sure thing! Here’s the link http://info.mcm.edu/online-degree/e.html

I updated the dropdown menu to a checkbox, and it looks like the values are being successfully converted to True and False.

Is there any solution for converting values to a Boolean field?

Thanks!