I am a beginner to javascript ! I am trying to call a function from another function inside the same script tags. When I do this without sending arguments it works fine but when i do that with arguments that another function is not called..
Here is what I am doing
function measurement_convert()
{
var mc = "Measurement Conversion";
txt = "<h2>" + mc + "</h2> <br><br>";
txt +=
"<form action='' method='post'>" +
"Select Type <select name='conversion_type' onchange='loadXML('abcd')'> "+
"<option value='area'>Area</option>"+
"<option value='length'>Length</option>"+
"<option value='volume'>Volume</option>"+
"<option value='weight'>Weight</option>"+
"</select> <br><br>"
document.getElementById("content_main_top").innerHTML=txt;
}
So, I am calling the function from onchange of this form.
And here's the another function
function loadXML(var1)
{
document.getElementById("content_main_top").innerHTML=null;
document.getElementById("content_main_bottom").innerHTML=null;
}
Can anyone help me ?
2 Answers 2
Your problem is that you are trying to nest the same type of quote:
onchange='loadXML('abcd')'
This actually gets interpreted as:
onchange='loadXML('
Instead, try (note the escaped double-quotes, since this code is inside a PHP string):
Select Type <select name=\"conversion_type\" onchange=\"loadXML('abcd')\">
Comments
Your single quotes are clashing in the onchange value, as you use the same for closing the value in.
You can change it to:
"Select Type <select name='conversion_type' onchange=\"loadXML('abcd')\"> "
loadXML(var)function is not called indeed nothing happens