Announcement

Collapse
No announcement yet.

Javascript - Focus on input field on page load

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript - Focus on input field on page load

    First off, I in 'no' way take credit for writing this script. I just found it on 'google'. (Sorry, I can't remeber where.).

    What I did was took the javascript and made a super simple function out of it, to save typing so you can use it on all your pages you want. Sorry, I don't have an example of this, I don't have hosting for my engine (yet). So I have nothing online to show this. I made this for my engine. But it's just a function so it will work on anything..

    Here is the function (Don't talk bad about it. It's VERY simple, not complex. I Know that there are lots of ways of doing this.).

    PHP Code:
    function focus'$form,$input)
    {
        echo '
    <script type="text/javascript" language="JavaScript">';
        echo "document.forms['".
    $form."'].elements['".$input."'].focus();";
        echo '
    </script>';

    Now it used in action. (Just an example so please don't pick at it. or try to talk bad about it.

    PHP Code:
    echo '
    <form action="PAGENAME" method="post" name="form_name_here">
    <input type="text" name="input_name" value="Nothing" />
    <input type="submit" value="Do It" />
    </form>'
    ;
    //Now we use the function.
    focus('form_name_here','input_name');
    //Yes it MUST be AFTER the FROM! <-- Very important or it will not work.
    //First name is forms name. <-- In example it is (form_name_here)
    //Second is the Inputs name that you want it to put the cursor on when loaded. <-- In example it is (input_name)
    //Now, when they load the page it will put the cursor in that input everytime :) 
    Hope you enjoy, yeah I know this is really nothing special. But I'm sure there are lots of people like me that are lazy :P. I use stuff like this all the time to save typing.
    I'm sure everyone is going to say how they would have done it, lol..

    But that is ok :thumbsup:
    [paypal][email protected][/paypal]
    [progressbar=8,#0000FF,#000000]My Codes[/progressbar]

  • #2
    Nice one AlabamaHit strangely enough I've not thought about doing this (perhaps when you hit the homepage username is focussed.. Good find :thumbsup: )
    "We believe that bad sex and good drugs are the cornerstones of a great democracy."
    - P.A.G.A.N
    Will you be (Mg,Fe)7Si8O22(OH)2 ?



    Comment


    • #3
      Yeah on the engine I'm working on, I'm making the page focus on the first input on any page that has an input..

      So, if using mccodes, I would agree completely, pages like login, register, bank, home page(index) focus on notepad, etc...

      In mccodes I would put it in the global function page, But if using on login, you will have to put it on the page. So really wouldn't need the functnion. Just adding the javascript itself to pages like that.
      [paypal][email protected][/paypal]
      [progressbar=8,#0000FF,#000000]My Codes[/progressbar]

      Comment


      • #4
        Yeah it's really the simple things that count I'll be using this for sure thanks again
        "We believe that bad sex and good drugs are the cornerstones of a great democracy."
        - P.A.G.A.N
        Will you be (Mg,Fe)7Si8O22(OH)2 ?



        Comment


        • #5
          No problem, glad you like it.

          I was hoping that people would find it useful.
          [paypal][email protected][/paypal]
          [progressbar=8,#0000FF,#000000]My Codes[/progressbar]

          Comment


          • #6
            I'm sure others will be using it just not acknowledging the poster (normal XD)
            "We believe that bad sex and good drugs are the cornerstones of a great democracy."
            - P.A.G.A.N
            Will you be (Mg,Fe)7Si8O22(OH)2 ?



            Comment


            • #7
              Yeah your probarly right, lol.
              [paypal][email protected][/paypal]
              [progressbar=8,#0000FF,#000000]My Codes[/progressbar]

              Comment


              • #8
                Yeah :P

                Maybe we should create a whole topic on helpfull snippets and sticky it for future reference (just throwing out ideas here :P )
                "We believe that bad sex and good drugs are the cornerstones of a great democracy."
                - P.A.G.A.N
                Will you be (Mg,Fe)7Si8O22(OH)2 ?



                Comment


                • #9
                  I like it. Will use it.

                  Thanks
                  Ruler of Zu

                  FIA ISP FTW!

                  MWG a discussion forum. If you do not like replies then perhaps dont start a topic.

                  I no longer support Mccodes bugs, errors or security flaws either on the forum or by private message due to the lack of support by the mccodes staff for their own engine.

                  If your looking for an engine get one thats supported by its staff. EzRPG and EzRPG Rework & NWE are my recommendations.

                  Comment


                  • #10
                    This is just accessibility enhancement to a website, there are allot of other factors that one has to look at.
                    From simple tab indexes to accessibility for colour blind people, and even people who are deaf.

                    Comment


                    • #11
                      Yup exactly. Just makes it quicker and easier, because it loads you in the field your typing in already. (Also, remeber, I just found the code online. I didn't write it up. Just made a function out of it.)
                      [paypal][email protected][/paypal]
                      [progressbar=8,#0000FF,#000000]My Codes[/progressbar]

                      Comment

                      Working...
                      X