...

View Full Version : attachEvent("onclick",function(argument)):Error



newboy
04-04-2003, 08:57 PM
Hi friends

I wrote this code by attachEvent
-----------------------------------------------
<input type="Button" name="bt1" value="test">
<script>
function func1()
{
alert("nonargument")
}
bt1.attachEvent("onclick",func1)
</script>
----------------------------------------------
Its work well ,but I want give to func1() an argument:
-----------------------------------------------
<input type="Button" name="bt1" value="test">
<script>
function func1(number)
{
alert(number)
}
bt1.attachEvent("onclick",func1(15))
</script>
----------------------------------------------
But this will eventuate an error!
Why?

beetle
04-04-2003, 09:07 PM
The 2nd argument for attachEvent must be a function pointer, and not an actual function call. You can get around this with an anonymous function that calls your function with a parameter.

bt1.attachEvent("onclick", function() { func1(15) } )

ConfusedOfLife
04-04-2003, 11:25 PM
Also don't forget to write your code inside the [ code ] and [ /code ] tags my fellow iranian friend! :D

Something like:



<input type="Button" name="bt1" value="test">
<script>
function func1()
{
alert("nonargument")
}
bt1.attachEvent("onclick",func1)
</script>

newboy
04-05-2003, 03:29 AM
thank u , dear bijan ;)

ConfusedOfLife
04-05-2003, 11:42 AM
You have to thank beetle for giving you the code not me silly boy! And you're not using that code tag correctly, you should have commented that line, since it's not a code! BTW how do you know my name?!

Weirdan
04-05-2003, 12:05 PM
May be from your signature? :)

ConfusedOfLife
04-05-2003, 08:34 PM
No, I actually saw him tonight! He's a new guy at our company and I gave him the address of here myself!! Oh God, I'm getting famous! :D

newboy
04-06-2003, 05:45 AM
1-please excuse me guys; i am a beginer

2-thank you [very much] beetel

3-here is a very good place for me and for all of beginer developers and i will stay here untill end of my life!

4-but u bijan, this is for you:


<script>
alert(" thank u dear bijan ;) ")
</script>


my mind mind at first was this, but u aren't very clever :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum