Click here to Skip to main content
15,937,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello please take a look at my code below

<script type="text/javascript">
var vsize; //global variable
function veg7()
{
vsize=7;
}
function veg10()
{
vsize=10;
}
function getCBP()
{
if(vsize==7)
  {
    alert(vsize);
  }
else{
  alert(vsize);
}
}
</script>



if any event access the function veg7() and function veg10() (it is dynamic) and changes the value of vsize accordingly then why am i getting vsize as undefined.

please help me..i need the value of vsize in getCBP().
Posted

vsize will be undefined until it is set i.e. veg10() or veg7() is called.

Try this instead:
JavaScript
var vsize=0; //global variable
 
Share this answer
 
Comments
CPallini 21-May-15 5:59am    
of course, 5.
Mehdi Gholam 21-May-15 7:39am    
Cheers!
Here variable declared but not set value. First you need to set value either by calling veg7() function or veg10() function, then you will get value in getCBP() function.

var vsize; //global variable

function veg7()
{
vsize=7;
}
function veg10()
{
vsize=10;
}
function getCBP()
{
if(vsize==7)
{
alert(vsize);
}
else{
alert(vsize);
}
}
function init(){
veg7();
}
init();
getCBP();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900