0

How to reset the lookup value to None in Editform.aspx page using Jquery.

I want to empty the lookup dropdown if text box does not have any value . Here is the code which i have tried.I was able to set the value but it is adding ('None') in the look up drop down. When i click on save it is showing the selected value .

Note: By lookup has more than 20+ items.

$("input[title='"+NumStoreColName+"']").change(function()
    {
         var NoStoreVals =$("input[title='"+NumStoreColName+"']").val();
        if(NoStoreVals == "")
         {

             ResetDropDownList(hidelookup); 
         }
         else
         {

         }      
    });


function ResetDropDownList(lookupcolumnName) 
{
    lookupField = getField('select',lookupcolumnName); 
     lookupSelectedItem = lookupField.options[lookupField.selectedIndex]; 
     var test= lookupSelectedItem.value + "-" + lookupSelectedItem.text; 
     lookupSelectedItem.text='(None)';
}

function getField(fieldType,fieldTitle) {  
      var docTags = document.getElementsByTagName(fieldType);  
      for (var i=0; i < docTags.length; i++) {  
          if (docTags[i].title == fieldTitle) {  
              return docTags[i];  
          }  
      }  
      return false;  
} 

1 Answer 1

0

I was able to get this working if my lookup has less tahn 20 items. However it is not working if i has more than 20 + items in Ie10.

function ResetDropDownList(lookupcolumnName,NumStoreColName) 
{

     if(getField('select',lookupcolumnName))
     {
         getField('input',NumStoreColName).value='';
         $("select[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');

     }
  else  
    { 
    $("input[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');
     getField('input',NumStoreColName).value='';
    }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.