function func1(str)
{

 document.getElementById("txtHint").innerHTML='<Br>Graph type: <select id="sel"  name="sel" onchange="func2(str)"><option value="1">1</option><option value="2"> 2</option></select>';

}

function func2(x)
{

some codes....

}

In Above coding,

i want to pass the "str" variable to "func2" in onchange .

but above code is not working.

Can anyone Please help me..?

3D,

//This is the bad way
function func1(str){
  document.getElementById("txtHint").innerHTML = '<br>Graph type: <select id="sel" name="sel" onchange="func2(\'' + str + '\')"><option value="1">1</option><option value="2"> 2</option></select>';
}

//This is preferred
function func1(str){
  document.getElementById("txtHint").innerHTML = '<br>Graph type: <select id="sel" name="sel"><option value="1">1</option><option value="2"> 2</option></select>';
  document.getElementById("sel").onchange = function(){
    func2(str);
  };
}

For a number of reasons, event handlers are better attached in javascript than in HTML.

Airshow

commented: It is very helpful +1

Thankyou verymuch.i solved my problem.your answer was very helpful to me... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.