locked
Retrieve value from the webresource with HTML code in CRM 2011 form field RRS feed

  • Question

  • I have added a Check box using HTML code in web resource and used that web resource in MS CRM 2011 form and there I want to retrieve the values of the selected options of check box and add those values and save them in a text field. I really need help to resolve this issue and if there is some alternative please let me know.
    Wednesday, June 20, 2012 5:11 AM

All replies

  • You can achieve it by getting the value of those checkbox inside that web resource iframe.

    Here's the sample code. (replace "WebResource_HTMLPage" with your webresource name)

    if (Xrm.Page.getControl("WebResource_HTMLPage").getObject().contentWindow.document.getElementById("chkbox1").checked)
       Xrm.Page.getAttribute("new_textfield").setValue("Checked");
    else
       Xrm.Page.getAttribute("new_textfield").setValue("Unchecked");

    Another way is that you can also set the value into the text field of CRM from the webresource.

    if (document.getElementById("chkbox1").checked)
       parent.Xrm.Page.getAttribute("new_textfield").setValue("Checked");
    else
       parent.Xrm.Page.getAttribute("new_textfield").setValue("Unchecked");

    Wednesday, June 20, 2012 6:54 AM
  • Hi,

    Sample code:

    function CheckboxChange(checkbox) {
        if (checkbox.checked == true) {
            alert(checkbox.value);
        }
    }

    function LoadIframeContent() {
      var myIFrame = document.getElementById('IFRAME_test');
     
      if (!myIFrame || !myIFrame.contentWindow || myIFrame.readyState !== 'complete') {
     
      window.setTimeout(LoadIframeContent, 10);
     }
      else if (myIFrame.contentWindow.document == null) {

     window.setTimeout(LoadIframeContent, 10);
      }
      else if (myIFrame.contentWindow.document.body == null) {

      window.setTimeout(LoadIframeContent, 10);
      }

     else {

      if (myIFrame.contentWindow.document.getElementById("chkTest") != null) {
          var checkbox = myIFrame.contentWindow.document.getElementById("chkTest");
          checkbox.attachEvent("onchange", function () { CheckboxChange(checkbox) });

     }
      }
      }
      window.setTimeout(LoadIframeContent, 10);


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. -------------------------------------------------------------------------------- Jhansi

    Wednesday, June 20, 2012 8:32 AM