0

I tried to get the text-box's id via its event function but it seems $a doesn't work because the system understands this as text, what should I do?

<select class="btn btn-outline-secondary dropdown-toggle"
        type="button"
        class="dropdown-menu" 
        onchange="validateSelectBox(this,'skill_input4')">

<select class="btn btn-outline-secondary dropdown-toggle"
        type="button"
        class="dropdown-menu" 
        onchange="validateSelectBox1(this,'skill_input3')">
function validateSelectBox(obj, $a){
  
    var options = obj.children;
 
    var html = '';
 
    for (var i = 0; i < options.length; i++){
        if (options[i].selected){
            html += options[i].value;
        }
    }
    // this is the error, the textbox does not change data
    // when I select the combobox
    document.getElementById('$a').value = html; 
}

4
  • Why two types of class in each select - Also where is the textbox ? Commented Aug 24, 2020 at 4:53
  • Can you kindly share a working fiddle? That will help us in understanding the problem statement. Commented Aug 24, 2020 at 4:53
  • remove quotes of $a : document.getElementById($a).value Commented Aug 24, 2020 at 4:56
  • $a that NOT right. Its Javascript not PHP => use simple $a Commented Aug 24, 2020 at 4:56

5 Answers 5

2

You do not need to put it in quotes as sting as it's a variable,Can you try this

document.getElementById($a).value = html; 
Sign up to request clarification or add additional context in comments.

1 Comment

Also, you can use just variable name such as $ instead of prefixing any variable name with $.
0
  function validateSelectBox(obj, a)
{
  
    var options = obj.children;
 
    var html = '';
 
  
    for (var i = 0; i < options.length; i++){
        if (options[i].selected){
            html += options[i].value;
        }
    }
document.getElementById(a).value = html; 
}

1 Comment

Please always consider leaving a comment on what you and why it solved the op's problem
0

If skill_input3 and skill_input4 are the ids of the textbox as mentioned you should call document.getElementById($a).value=html

Comments

0
 function validateSelectBox(obj,$a)
{
  
    var options = obj.children;
 
    var html = '';
 
  
    for (var i = 0; i < options.length; i++){
        if (options[i].selected){
            html += options[i].value;
        }
    }
document.getElementById($a).value = html;//remove '$a' from quotes.
}

Remove'$a' From Quotes

Comments

0

You have to remove $a from quotes as it a variable

function validateSelectBox(obj,$a)
{
  
    var options = obj.children;
 
    var html = '';
 
  
    for (var i = 0; i < options.length; i++){
        if (options[i].selected){
            html += options[i].value;
        }
    }
document.getElementById($a).value = html;//remove '$a' from quotes.
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.