AlabamaHit Posted May 29, 2010 Share Posted May 29, 2010 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.). 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. 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: Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 29, 2010 Share Posted May 29, 2010 Nice one AlabamaHit strangely enough I've not thought about doing this (perhaps when you hit the homepage username is focussed.. Good find :thumbsup: ) Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted May 29, 2010 Author Share Posted May 29, 2010 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. Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 29, 2010 Share Posted May 29, 2010 Yeah it's really the simple things that count I'll be using this for sure thanks again :) Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted May 29, 2010 Author Share Posted May 29, 2010 No problem, glad you like it. I was hoping that people would find it useful. :) Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 30, 2010 Share Posted May 30, 2010 I'm sure others will be using it just not acknowledging the poster (normal XD) Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted May 30, 2010 Author Share Posted May 30, 2010 Yeah your probarly right, lol. Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 30, 2010 Share Posted May 30, 2010 Yeah :P Maybe we should create a whole topic on helpfull snippets and sticky it for future reference (just throwing out ideas here :P ) Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted May 30, 2010 Share Posted May 30, 2010 I like it. Will use it. Thanks Quote Link to comment Share on other sites More sharing options...
Spudinski Posted May 30, 2010 Share Posted May 30, 2010 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. Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted May 30, 2010 Author Share Posted May 30, 2010 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.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.