I am using InjectJsScript activity for selecting item from dropdown. For a particular item, below code is being used which is in a js file and It works fine.
function (){
document.querySelector(“#ContentPlaceHolder1_ddlDoctor”).value=‘4411’
}
But I don’t want to maintain separate files for each element. So, I changed code like below.
function (name){
switch(name){
case ‘xxxx’:
document.querySelector(“#ContentPlaceHolder1_ddlDoctor”).value=‘4411’;
break;
case ‘yyyyy’:
document.querySelector(“#ContentPlaceHolder1_ddlDoctor”).value=‘1406’;
break;
}
}
But above code is not working. Kindly assist me on this.
Hello. Why don’t you try to set just the value in the switch and then call query selector?
The visibility of the selector variable could not be proper inside the switch statement.
The JavaScript function may look like this:
function(name){
var choice = ‘’;
switch(name){
case ‘xxxx’:
choice=‘4411’;
break;
case ‘yyyyy’:
choice=‘1406’;
break;
}
if (choice == “”) return;
document.querySelector(“#ContentPlaceHolder1_ddlDoctor”).value=choice;
}
If this is not working, that means the name argument is not well passed.
With fine regards, Adrian
It can be used simple quotes ( ’ ) for string constants, or double quotes.
Perhaps a language setting for the keyboard for ‘English US’ will solve this issue.
About passing the name argument, there can be also a problem.
Actually the script can be used without any argument, and you can get the name as a value from another control, also using document.querySelector.
If querySelector is not working, you can also try with document.getElementById