i hava two question :
1 – for function with input value how i can set interval i test this but now working
<script>
function bn(x)
{
alert (x);
}
setInterval("bn(x)",3000);
</script>
<a href="#" onclick="bn(1);">bn 1</a><br>
with setInterval("bn()",3000); work but show ‘undefine’ insteadof ‘1’
an 2- how Set repeat for two value mean when repeat this function i try for new value and function repeat for two value
<script>
function bn(x)
{
alert (x);
}
setInterval("bn(x)",3000);
</script>
<a href="#" onclick="bn(1);">bn 1</a><br>
<a href="#" onclick="bn(2);">bn 2</a>
Okay, I think I understand what you want; see below:
For your first question, what you are currently doing will obviously not work(as you’ve likely figured out). To fix that, you must use an anonymous function; example below:
As to your second question, see the last two lines above; as the function is already running all you need to control is the value of
x, and make sure you set its scope as general, as opposed to specific to the function in which it is used.The onclick events set the value of
x. I’ve made sure the code works; if the value is set to2, then the alert will display2, etc.