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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    argument declaration in form1.arg.focus();

    Hi,

    How can I put the argument - arg - in - form1.arg.focus(); - that it works?

    the value of arg = the name of an input-field
    form1 = the name of the form in which the input-field is located

    function func(arg)
    {
    form1.arg.focus();
    }

    Thanks,
    Jerome

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure if I understand your question

    <script>

    function func(arg)
    {
    document.form1.arg.focus()
    }

    </script>
    <form name="form1">
    <input name="arg">
    </form>
    <input type="button" onclick="func('arg')">

    <edit>
    opps, doesn't work if you change arg to something else. I'll check further
    </edit>
    Last edited by Graeme Hackston; 07-13-2003 at 02:56 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, brain fade. Here you go

    <script>

    function func(arg)
    {
    document.form1[arg].focus();
    }

    </script>
    <form name="form1">
    <input name="arg1">
    </form>
    <input type="button" onclick="func('arg1')">

  • #4
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works perfect, thanks Graeme

    I was a little confused, I wrote:

    form1.arg.focus();

    however it had to be:

    form1[arg].focus();

    Nice week-end!
    Jerome


  •  

    Posting Permissions

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