Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    iran
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    iran
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    thank u , dear bijan ;)

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?!

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    Somewhere far beyond
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    May be from your signature?
    WBR, Weirdan.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #8
    New Coder
    Join Date
    Mar 2003
    Location
    iran
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •