Solution 1 :

I’m not sure if it’s a copy-paste issue or you’re actually making a mistake here but it seems that your innerHtml string has enters in it. It doesn’t automatically concat the values for you. You can specify a after each breakpoint. In all honesty there are alot of ways of solving this. Please see this link for some more guidance

document.getElementById("mydiv").innerHTML ="<div class='form-group'><label>Color Option</label> 
                 <select name='mycolor' onchange='javascript:fshowMe("+this+")' id='mycolor' class='form-control input-lg' required> 
                 <option value='black'>Black</option>";

document.getElementById("mydiv2").innerHTML ="<div class='form-group'><label>Color Option</label> <select name='mycolor' onchange='javascript:fshowMe("+this+")' id='mycolor' class='form-control input-lg' required><option value='black'>Black</option>";
<div id="mydiv"></div>
<div id="mydiv2"></div>

Problem :

I want to add some select option tag in HTML with script below, but when select option successfully loaded, it always return without onchange='javascript:fshowMe("+this+")'

if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
            {                 
                 document.getElementById("mydiv").innerHTML ="<div class='form-group'><label>Color Option</label>
                 <select name='mycolor' onchange='javascript:fshowMe("+this+")' id='mycolor' class='form-control input-lg' required>
                 <option value='black'>Black</option>";     
            }
            return false;

result like this

<select name="mycolor" id="mycolor" class="form-control input-lg" required="">
    <option value="black">Black</option> 

i expected the result was this

<select name="mycolor" id="mycolor" onchange="javascript:fshowMe(this)" class="form-control input-lg" required="">
    <option value="black">Black</option>

how to show the onchange to my select option?

thanks you

Comments

Comment posted by Great Saiyaman

i actually want to show div triggered by other action, i have 3 multilevel select option, when option 1 selected, i want to show select option ‘mycolor’ with innerHTML with onchange properties, but it doesnt show onchange properties, but other properties like name=’mycolor’ etc was shown

Comment posted by how to write a good question here

I’m sorry but i’m a bit confused of what you’re asking.. In your question above you have stated that

Comment posted by Great Saiyaman

oh sorry, i use enter just on question. not for my script. i dnt khow how why is “onchange=”javascript:fshowMe(this)” always missing, from the result.

Comment posted by Scircia

Alright so the question is still the same. For me to be able to help you, you should edit your question and show the full code. I noticed you only showed a part of the code which on detecting whats wrong makes it nearly impossible. As i showed you in the example you can see that it works just fine so it could be that something else is causing the problem. Try to check your devtools if the console isn’t showing any errors. Try to log some elements like forexample your

By