SBX - Search With Button

SBX - Forum Post Title

Set Two option set value in Portal using Javascript

Microsoft Dynamics CRM Forum

Shahbaaz Ansari asked a question on 1 May 2018 1:22 AM
My Badges

Question Status

Verified

Hi All,

I am trying to set Two option value from javascript but i am unable to do so, i have also set text field which is working fine,

below is my code,

$(document).ready(function(){

$('#tt_needs').val('test'); // text field which is working fine

$('#adx_partnercreated').val('1'); // unable to set two option set value

});

Thanks,

Shahbaaz

Reply
Suggested Answer

Hi Shahbaaz,

If it is checkbox or radio button then try below syntax:

$('#element').prop('checked', true);

If it is dropdown:

$("#element").val("1");

Hope it helps.

Reply
Shahbaaz Ansari responded on 1 May 2018 2:54 AM
My Badges

it is radio button i used below code,

$(document).ready(function(){  

  $('#adx_partnercreated').prop('attribute', true);

});

not working

Reply
Shaminderpal Singh responded on 1 May 2018 3:14 AM
My Badges
Verified Answer

Hi Shahbaaz ,

You can set the value using below

Replace checkemail with your schema

$(function(){

$('#checkemail  #checkemail_0').prop('checked',true); //Set No value

$('#checkemail  #checkemail_1').prop('checked',true);//Set Yes value

});

I have tested it as well  .Below is the screenshot.

-Shaminder

Reply
Verified Answer

Each radiobutton has its own element Id. So Try this:

$('#adx_partnercreated_0').prop('checked', true);

$('#adx_partnercreated_1').prop('checked', true);

Hope it helps.

-Arpit

Reply
Shahbaaz Ansari responded on 1 May 2018 3:37 AM
My Badges

thanks shaminderpal, it worked.

@aprit : i tried $('#adx_partnercreated').prop('checked', true); but not working

Reply

You need to append '_0' or '_1' along with element Id. Updated in my comment.

Reply
Shahbaaz Ansari responded on 1 May 2018 4:13 AM
My Badges

Hi Arpit/Singh,

I have set the field value, this field is either hidden/Readonly, but when i make it as Hidden or readonly it is not setting the value of radio button to "YES"

Thanks,

Shahbaaz

Reply
Suggested Answer

Field must be present on the Portal Form. If you will turn off it's visibility from CRM form. It will not render on the portal and won't work.

If you want to make the field readonly, then first set it's value true/false and then make it readonly instead of making it readonly first.

Hope it helps.

-Arpit

Reply
Shahbaaz Ansari responded on 1 May 2018 4:26 AM
My Badges

thanks arpit for the reply, below is the code i hide the field portal side and set the value

$(document).ready(function(){  

 $('#adx_partnercreated').closest('.boolean-radio-cell').addClass('hidden');

  $('#adx_partnercreated  #adx_partnercreated_1').prop('checked',true);

});

Reply
Suggested Answer

Did you try setting the value before making it Hidden/Readonly.

Like this:

$(document).ready(function(){  

$('#adx_partnercreated  #adx_partnercreated_1').prop('checked',true);

$('#adx_partnercreated').closest('.boolean-radio-cell').addClass('hidden');

});

Reply
DhivyaSivasankkar responded on 11 Feb 2019 2:23 PM

This is great! How would I check if the radiobutton is checked or not in the Dynamics Portal?

Reply
Arpit Shrivastava responded on 11 Feb 2019 10:59 PM
My Badges
Suggested Answer

Hi Divya,

Please try following code:

if($('adx_partnercreated_0').prop("checked") == true)

{

alert("Rafiobutton is checked." );

}

else if($('adx_partnercreated_0').prop("checked") == false)

{

alert("Radiobutton is unchecked." );

}

Hope it helps.

Cheers

Arpit

Reply
Shaminderpal Singh responded on 1 May 2018 3:14 AM
My Badges
Verified Answer

Hi Shahbaaz ,

You can set the value using below

Replace checkemail with your schema

$(function(){

$('#checkemail  #checkemail_0').prop('checked',true); //Set No value

$('#checkemail  #checkemail_1').prop('checked',true);//Set Yes value

});

I have tested it as well  .Below is the screenshot.

-Shaminder

Reply
Verified Answer

Each radiobutton has its own element Id. So Try this:

$('#adx_partnercreated_0').prop('checked', true);

$('#adx_partnercreated_1').prop('checked', true);

Hope it helps.

-Arpit

Reply
Suggested Answer

Hi Shahbaaz,

If it is checkbox or radio button then try below syntax:

$('#element').prop('checked', true);

If it is dropdown:

$("#element").val("1");

Hope it helps.

Reply
Suggested Answer

Field must be present on the Portal Form. If you will turn off it's visibility from CRM form. It will not render on the portal and won't work.

If you want to make the field readonly, then first set it's value true/false and then make it readonly instead of making it readonly first.

Hope it helps.

-Arpit

Reply
Suggested Answer

Did you try setting the value before making it Hidden/Readonly.

Like this:

$(document).ready(function(){  

$('#adx_partnercreated  #adx_partnercreated_1').prop('checked',true);

$('#adx_partnercreated').closest('.boolean-radio-cell').addClass('hidden');

});

Reply
Arpit Shrivastava responded on 11 Feb 2019 10:59 PM
My Badges
Suggested Answer

Hi Divya,

Please try following code:

if($('adx_partnercreated_0').prop("checked") == true)

{

alert("Rafiobutton is checked." );

}

else if($('adx_partnercreated_0').prop("checked") == false)

{

alert("Radiobutton is unchecked." );

}

Hope it helps.

Cheers

Arpit

Reply

SBX - Two Col Forum

SBX - Migrated JS