locked
Convert Text Field to a Picklist AND include an OnChange event RRS feed

  • Question

  • Hey all,

       I am using some excellent code from Stunware CRM to convert a text field to a pick list.

       When I select different values, I want an OnChange event to trigger; but I can't seem to make this happen. I think this is because the text field I convert is actually REPLACED by the picklist, hence the Onchange Event is tied to a text field that no longer appears on the Form.

    How can I trigger an event by changing the selected value in my converted field?

    Thanks again.

    Al
    Friday, March 20, 2009 8:12 PM

Answers

  • Hi,

    1. crmForm.all.<field>.onchange = function() {<your code>}
    Instead of clicking in on the field, to define the change event, you define it on form load.
    Here is an example, where I have declared a change event in form load:
    crmForm.all.new_item1.onchange = function() {
    if (crmForm.all.new_item1.DataValue != null) crmForm.SetFieldReqLevel("new_responsible1",1); else crmForm.SetFieldReqLevel("new_responsible1",0); }

    2. When Value is selected
    Your value will be stored as text in your original text field

    3. Update another field
    yes, no problem, just add code for that in your onchange event, as described in 1.

    crmForm.all.<text field>.DataValue = crmForm.all.<your combo>.DataValue



    Monday, March 23, 2009 2:28 PM

All replies

  • Hi,

    I have used this function to convert text to combo (probably same as you):

    function setCombo(fieldName, options, tabidx)
    {
       var defaultValue = crmForm.all.item(fieldName).DataValue;
       var table = crmForm.all.item(fieldName + "_d");
       var select = "<select req='0' id='" + fieldName + "' name='" + fieldName + "' defaultSelected='' class='ms-crm-SelectBox' tabindex='" + tabidx +"'>";
       var defaultValueFound = false;
       for (index in options) {
          select += "<option value='" + options[index] + "'";
          if (options[index] == defaultValue) { select += " SELECTED"; defaultValueFound = true; }
          select += ">" + options[index] + "</option>";}

         if ((defaultValue != null) && (defaultValue.length > 0) && !defaultValueFound) {   select += "<option value='" + defaultValue + "' SELECTED>" + defaultValue + "</option>";}
        select += "</select>";
        table.innerHTML = select;
    }

    and after chat i redefine the onchange event for that spesific field (typically in form load, but always after re-loading your combo),
    crmForm.all.<field>.onchange = function() {<your code>}

    I'm quit sure there is a way to extract the change event, and then re-attach that to the new field ... but I have not seen the need for that yet. Even thogh it would have been more sophisticated.



    Sunday, March 22, 2009 9:04 PM
  • Morten,

       Thank you for the reply. can you elaborate a little on what "crmForm.all.<field>.onchange = function() {<your code>}" does? When my form loads, the text field is replaced with the Picklist. What actually happens when a value is selected?

       In my case, I would like another text field to update itself with the value selected from the picklist. Can this be done?

    Al
    Monday, March 23, 2009 2:18 PM
  • Hi,

    1. crmForm.all.<field>.onchange = function() {<your code>}
    Instead of clicking in on the field, to define the change event, you define it on form load.
    Here is an example, where I have declared a change event in form load:
    crmForm.all.new_item1.onchange = function() {
    if (crmForm.all.new_item1.DataValue != null) crmForm.SetFieldReqLevel("new_responsible1",1); else crmForm.SetFieldReqLevel("new_responsible1",0); }

    2. When Value is selected
    Your value will be stored as text in your original text field

    3. Update another field
    yes, no problem, just add code for that in your onchange event, as described in 1.

    crmForm.all.<text field>.DataValue = crmForm.all.<your combo>.DataValue



    Monday, March 23, 2009 2:28 PM