0

I am trying to set Look Up Drop down using JavaScript/Jquery. I am able to set the value but while saving by default 1st option in drop down is Set.

Thanks in Advance...!!!

  • you have to set value in this format -> 12;#Value – Gaurravs Dec 10 '15 at 10:02
  • can you add your code? – Atish Dipongkor - MVP Dec 10 '15 at 10:02
  • item ID of the lookup value from where it actually exists and the value of that field – Gaurravs Dec 10 '15 at 10:02
2

native Javascript, no jQuery

function setOption( selector , value , allowMultiple ){
  var options=document.querySelector( selector ).childNodes;
  for(var i=0;i<options.length;i++){
    var option=options[i];
    if (!allowMultiple) option.removeAttribute('selected');
    if (option.getAttribute('value')===value || i===value+1) option.setAttribute('selected','selected');
  }
}

//set one value by name 
setOption( "select[title='Task Status']" , 'Completed' , false );

//set multiple values by number
setOption( "select[title='Task Status']" , 1 , true );
0

Code below helped me to set the LookUp value of DropDown in default edit/new form of List

var ValuetoSet="test";
var FieldToSet = $('select[title="Customer ID"]');
$.each(dataClsField[0],function(){if($(this).text() == ValuetoSet) {
    dataClsField.val(this.value);
}});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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