locked
JS getAttribute() doesn't work rigth RRS feed

  • Question

  • Hi,

    i've got a problem with javascript. See the code below, it's an onload function and will load if the user opens a crm-contact. "new_land" is a dropdown menu.

    function setVisibilitySonstigesLand()
    {
    var land= Xrm.Page.getAttribute("new_land").getSelectedOption().text;
    if (land == "Sonstige") 
    	{
    		Xrm.Page.ui.controls.get("address1_country").setVisible(true);
    		Xrm.Page.ui.controls.get("address1_country").setFocus();
    	}
    }

    The error is "cannot get a value for propertie "text" because the object is null or undefined".

    If i insert an alert("hi"); just before var land = Xrm.Page.getAttr...  it works without any problem.

    Can you tell me how i get it to work without alert("hi"); ?

    Thank you

    Volker


    Tuesday, January 7, 2014 10:44 AM

Answers

  • Hi,
    the correct function to get the text from an optionset is getText(), try with

    function setVisibilitySonstigesLand()
    {
    var land= Xrm.Page.getAttribute("new_land").getText();
    if (land == "Sonstige") 
    	{
    		Xrm.Page.ui.controls.get("address1_country").setVisible(true);
    		Xrm.Page.ui.controls.get("address1_country").setFocus();
    	}
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Tuesday, January 7, 2014 11:16 AM
    • Marked as answer by volker.it Tuesday, January 7, 2014 11:38 AM
    Tuesday, January 7, 2014 11:16 AM

All replies

  • Hi,
    the correct function to get the text from an optionset is getText(), try with

    function setVisibilitySonstigesLand()
    {
    var land= Xrm.Page.getAttribute("new_land").getText();
    if (land == "Sonstige") 
    	{
    		Xrm.Page.ui.controls.get("address1_country").setVisible(true);
    		Xrm.Page.ui.controls.get("address1_country").setFocus();
    	}
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Tuesday, January 7, 2014 11:16 AM
    • Marked as answer by volker.it Tuesday, January 7, 2014 11:38 AM
    Tuesday, January 7, 2014 11:16 AM
  • Thank you, that helped!
    Tuesday, January 7, 2014 11:39 AM