Forwarding a variable within a function (javascript)

  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

If I have a function that takes a variable, and then I call a function within it, how do I give the second function the first variable?

This is what I want to do:

func1 gets variable x->calls func2->gives variable x to func2
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Tannu4u
  • Proficient
  • Proficient
  • User avatar
  • Posts: 480
  • Loc: India

Post 3+ Months Ago

function amt1(str)
{
function amt2(str);
}



function amt2(result)
{
alert(result);
}

I thin this is waht u want to do,am i wright,if the problem is solved its great to see it.
  • zudo
  • Beginner
  • Beginner
  • zudo
  • Posts: 35

Post 3+ Months Ago

thanks!
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

OR if you var the variable outside of the first function then that variable is accessible by all the functions into those script tags ie:
Code: [ Select ]
<script>
var i;
function1(){
 i = 2
}
function2(){
   n=i+2;
   alert(n);
}
</script>
  1. <script>
  2. var i;
  3. function1(){
  4.  i = 2
  5. }
  6. function2(){
  7.    n=i+2;
  8.    alert(n);
  9. }
  10. </script>
it would alert 4

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 116 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.