<html>
<head>
<script type="text/javascript">

var flag=0;
 
callf()
 {
  if(flag == 0)
   {
    test()
     {
       alert("hi from if");
     }
   }

else
  {
    alert("hi from else");
  }
 }



</script>

</head>
<body>

 <input type="text" onchange="callf();">

</body>
</html>

what's wrong with this code ??
nothing happens when i type into the text box..

function callf(flag) <- this variable will need to be set somewhere unless you are declaring a global variable.
{

is test(); supposed to be a function? if so is it returning a value?
.......
}

isn't flag a global variable here ??

The point I was trying to make was that the variable flag was used within the function callf. Therefore does it need to be a global variable?

Once passed that stage you have to use function callf() not just callf() to define what happens within the function

You also have a line test() if this is calling a separate function then that will have to be visible somewhere within the code or an include.

<html>
<head>
<script type="text/javascript">

var flag=0;
 
function callf()
 {
  if(flag == 0)
   {
       alert("hi from if");
   }

else
  {
    alert("hi from else");
  }
 }



</script>

</head>
<body>

 <input type="text" onchange="callf();">

</body>
</html>

This does work and the alert box does come up.

<html>
<head>
<script type="text/javascript">

var flag=1;
 
function callf()
 {
  if(flag == 0)
   {
       alert("hi from if");
   }

else
  {
    alert("hi from else");
  }
 }



</script>

</head>
<body>

 <input type="text" onchange="callf();">

</body>
</html>

even the call the "hi from if"
shouldn't it be "hi from else " ??

you are right that your code would indeed return 'hi from else' but in the test that I had done I had set the flag variable to 0;

yups...
but i was talking about the code i have posted...
what does it return for u ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.