Skip Navigation

[Resolved] Show/Hide Options and select a different Default Option in CRED Select field

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to set a default value for their checkbox using jQuery.

Solution:
This can be done by using the code below.
jQuery('select option[value="1"]').attr("selected",true);

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by SatinS5964 6 years ago.

Assisted by: Shane.

Author
Posts
#1146671

I have a User - Custom field which is of type "Select".

I show this field on a User CRED Form.

1. I want to be able to hide one of the options.
I tried using this JS code which I got from another issue. But it does not seem to be working.

Field on CRED Form:

	<div class="form-group">
		<label>User Type</label>
		[cred_field field='my-field' force_type='field' class='form-control' output='bootstrap']
	</div>

JS Code used (but NOT working):

jQuery( document ).ready(function() {
    jQuery('#my-field select option[value="STA"]').hide();
});

2. I also want to select a different DEFAULT option than the one I setup when creating that field. How would I do that?

Thank you
Satin

#1146735

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Satin

Thank you for contacting our support forum.

I was able to do a short search and found this solution.
https://stackoverflow.com/questions/41383884/js-hide-options-based-on-value-attribute

This should be able to assist you with hiding your particular option.

Also for your default option you can try using this js.

jQuery('select option[value="1"]').attr("selected",true);

Please let me know if this helps.
Thanks,
Shane

#1146748

Thank you. That works for my solution.

#1146753

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Satin,

If there are no further issues on this then you can mark this ticket as resolved.

Thanks,
Shane

#1146765

My issue is resolved now. Thank you!