Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-04-2003, 07:57 PM   PM User | #1
newboy
New Coder

 
Join Date: Mar 2003
Location: iran
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
newboy is an unknown quantity at this point
attachEvent("onclick",function(argument)):Error

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?
newboy is offline   Reply With Quote
Old 04-04-2003, 08:07 PM   PM User | #2
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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) } )
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 04-04-2003, 10:25 PM   PM User | #3
ConfusedOfLife
Regular Coder

 
Join Date: Jul 2002
Location: Iran
Posts: 695
Thanks: 0
Thanked 0 Times in 0 Posts
ConfusedOfLife is an unknown quantity at this point
Also don't forget to write your code inside the [ code ] and [ /code ] tags my fellow iranian friend!

Something like:

Code:
<input type="Button" name="bt1" value="test">
<script>
function func1()
{
alert("nonargument")
}
bt1.attachEvent("onclick",func1)
</script>
ConfusedOfLife is offline   Reply With Quote
Old 04-05-2003, 02:29 AM   PM User | #4
newboy
New Coder

 
Join Date: Mar 2003
Location: iran
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
newboy is an unknown quantity at this point
Code:
thank u , dear bijan ;)
newboy is offline   Reply With Quote
Old 04-05-2003, 10:42 AM   PM User | #5
ConfusedOfLife
Regular Coder

 
Join Date: Jul 2002
Location: Iran
Posts: 695
Thanks: 0
Thanked 0 Times in 0 Posts
ConfusedOfLife is an unknown quantity at this point
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?!
ConfusedOfLife is offline   Reply With Quote
Old 04-05-2003, 11:05 AM   PM User | #6
Weirdan
New Coder

 
Join Date: Mar 2003
Location: Somewhere far beyond
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Weirdan is an unknown quantity at this point
May be from your signature?
__________________
WBR, Weirdan.
Weirdan is offline   Reply With Quote
Old 04-05-2003, 07:34 PM   PM User | #7
ConfusedOfLife
Regular Coder

 
Join Date: Jul 2002
Location: Iran
Posts: 695
Thanks: 0
Thanked 0 Times in 0 Posts
ConfusedOfLife is an unknown quantity at this point
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!
ConfusedOfLife is offline   Reply With Quote
Old 04-06-2003, 04:45 AM   PM User | #8
newboy
New Coder

 
Join Date: Mar 2003
Location: iran
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
newboy is an unknown quantity at this point
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:
Code:
<script>
alert(" thank u dear bijan ;) ")
</script>
my mind mind at first was this, but u aren't very clever
newboy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:25 AM.


Advertisement
Log in to turn off these ads.