0

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 ?

j08691
209k33 gold badges269 silver badges281 bronze badges
asked Sep 21, 2012 at 14:17
1
  • When I change the select option the loadXML(var) function is not called indeed nothing happens Commented Sep 21, 2012 at 14:19

2 Answers 2

3

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')\">
answered Sep 21, 2012 at 14:19
Sign up to request clarification or add additional context in comments.

Comments

1

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')\"> "
answered Sep 21, 2012 at 14:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.