2
 <script>
                $("select").change(function () {
  var str = "";
  var price = <?php echo $row[price];?>;
  $("select option:selected").each(function () {
            str += $(this).text() + " ";
  });
  $(".plan_price").text("price : " + parseInt(str)*price + " baht");
})
.change();
    </script>

So I got this .each and .change function here and I wanted to return the value of str from this whole functions so that I can use the str variable value in other places in my code

The problem I have is where to put the return and the name of the function when I call it somewhere else in my code like document.write(nameOfFunction) Please help

Thanks Alot !

Tony

1
  • Use "str" as global variable Commented Apr 2, 2013 at 6:56

1 Answer 1

1

In this case I think the only solution is to use a global variable to store the value

var myString;
$("select").change(function() {
    var str = "";
    var price = <?php echo $row[price];?>;
    $("select option:selected").each(function() {
                str += $(this).text() + " ";
            });
    $(".plan_price").text("price : " + parseInt(str) * price + " baht");
    myString = str;
}).change();
alert(myString)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.