ammu412 Posted September 22, 2008 Share Posted September 22, 2008 In my program function change_host(number,host){ alert(number+"---"+host) } function test(){ var num=1; var hostF="host"; newin.innerHTML = "<div id='er_clone"+num+"' style='display:inline;font-weight:bold;color:#FF2323;font-size:15px;'></div><center><table class='tblheaderbg' width=200><tr><th>Server Name</th><th>VM Machine Name</th><th>Vm Domain Name</th><th>VM IP</th><th>VM Net Mask</th><th>VM Gateway</th><th>VM DNS</th><th>Clone from template</th></tr><tr><td><select name='host_name"+num+"' id='host_name"+num+"' onChange='change_host("+num+","+hostF+");'>"; } In this when i'm calling change_host() function it says host is not defined. I don't know why it's happening...... Please give your valuable reply........... Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 22, 2008 Share Posted September 22, 2008 The problem is in your "creation" of the onChange event. The code will produce a trigger that looks something like this: onChange = 'change_host(1,host);' Where 15 is the value of the variable of num and host is the value of the variable hostF. Passing a number like that is fine. But, if 'host' is supposed to be a string then it needs to be properly formatted as such. Try this: function change_host(number,host){ alert(number+"---"+host) } function test(){ var num=1; var hostF="host"; var htmlCode = '<div id="er_clone"'+num+'" style="display:inline;font-weight:bold;color:#FF2323;font-size:15px;"></div>'; htmlCode += '<center><table class="tblheaderbg" width="200"><tr>'; htmlCode += '<th>Server Name</th>'; htmlCode += '<th>VM Machine Name</th>'; htmlCode += '<th>Vm Domain Name</th>'; htmlCode += '<th>VM IP</th>'; htmlCode += '<th>VM Net Mask</th>'; htmlCode += '<th>VM Gateway</th>'; htmlCode += '<th>VM DNS</th>'; htmlCode += '<th>Clone from template</th>'; htmlCode += '</tr><tr>'; htmlCode += '<td><select name="host_name'+num+'"'; htmlCode += ' id="host_name'+num+'"'; htmlCode += ' onChange="change_host('+num+', \''+hostF+'\');">'; newin.innerHTML = htmlCode; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.