How can I add a input text if a select option is right?

here is my code:

var sel1 = document.querySelector(’#sel1’);
var sel2 = document.querySelector(’#sel2’);
var options1 = sel1.querySelectorAll(‘option’);
var options2 = sel2.querySelectorAll(‘option’);
function giveSelection(selValue) {
sel2.innerHTML = ‘’;
for(var i = 0; i < options2.length; i++) {
if(options2[i].dataset.option === selValue) {
sel2.appendChild(options2[i]);
}
}
}
giveSelection(sel1.value);
var obj=document.getElementById(‘sel1’);
var index=obj.selectedIndex;
var val = obj.options[index].value;
function giveSelection(selValue){
if (selectedname.value==a){
iuput.style.opacity = 1;
}}
/if(val == 0){
iuput.style.opacity = 1;
}
/

I want to add a input text if the select value is “a” , so I use css of input text to control its opacity, but it doesn’t progress . How can I do? Thank you!

using jquery something like this you can get it:

var myTarget = $("#TargetId");
var myTargetValue = myTarget.val();

if(myTargetValue =="x"){
   myTarget.text("here is the text")
// or myAnotherTarget.text("here is the text")
}

There are some other ways you can do it. You may search it online