none
CRM 2011 - Dynamically set a radio button using JavaScript

    Question

  • I wonder if anyone knows the correct code to dynamically set a radio button in CRM 2011? I have two radio buttons with the name "isrevenuesystemcalculated". I would like to the second of these to be selected by default.

    Thanks,

    Dan

    Friday, February 22, 2013 10:08 AM

Answers

  • Hi Dan,

    Radio buttons are actually a single bit field. To set the values you can use :

     Xrm.Page.getAttribute('isrevenuesystemcalculated').setValue(true);

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by CSC Software Friday, February 22, 2013 10:56 AM
    Friday, February 22, 2013 10:20 AM
    Answerer

All replies

  • Hi Dan,

    Radio buttons are actually a single bit field. To set the values you can use :

     Xrm.Page.getAttribute('isrevenuesystemcalculated').setValue(true);

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by CSC Software Friday, February 22, 2013 10:56 AM
    Friday, February 22, 2013 10:20 AM
    Answerer
  • Thanks for your answer Scott. I wondered how it knows from this which of the two radio buttons to set?

    Dan

    Friday, February 22, 2013 10:24 AM
  • You have two bits fields or one bit field which will always have two option like Yes or No. First option is always false and second option is always true.

    Regards Faisal

    Friday, February 22, 2013 10:27 AM
  • I tried that but the first of the radio buttons is still selected.

    Regards,

    Dan

    Friday, February 22, 2013 10:39 AM
  • There must be some other code that is resetting it to false. Please make all other code inactive and than check. Also check that you are using the correct schema name of field.


    Regards Faisal

    Friday, February 22, 2013 10:45 AM
  • Why don't you set the radio button default value from the field settings?

    If the answer helped you, remember to mark it as answer.

    Friday, February 22, 2013 10:49 AM
    Moderator
  • Thanks Faisal. I've sorted it now, setting it to true was the default so to accomplish what I wanted, I needed to set it to false.

    Regards,

    Dan

    Friday, February 22, 2013 10:55 AM
  • Now that I've solved that one I wondered if a radio button can be disabled using a similar approach?

    Thanks,

    Dan

    Friday, February 22, 2013 11:07 AM
  • Use this to disable a field:

    Xrm.Page.ui.controls.get("schema name").setDisabled(true);


    If the answer helped you, remember to mark it as answer.

    Friday, February 22, 2013 11:25 AM
    Moderator
  • hi,

    May be this is useful

    var x= Xrm.Page.getAttribute("creditonhold").getValue();

    if(x==1)

    x.setValue(true);


    Wednesday, February 27, 2013 6:30 PM