0
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..?

2
Contributors
2
Replies
7
Views
5 Years
Discussion Span
Last Post by DILO3D
1

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

Edited by Airshow: n/a

Votes + Comments
It is very helpful
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.