Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Option to specify field for focus when form loaded

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Chowarmaan
Smarty n00b


Joined: 16 Aug 2013
Posts: 1

PostPosted: Fri Aug 16, 2013 5:19 pm    Post subject: Option to specify field for focus when form loaded Reply with quote

I am looking at a number of pages that all have different controls and visibility that are being built using Smarty templates. The common problem I find is that input pages do not have the first field active with the cursor in it.

I could write an OnLoad onto every page, but thought it would be better to be able to specify this with a attribute of the field for Smarty to take care of.

Is it possible to use something like a Focus attribute on fields, and the first visible one encounter (or first one period) would have the .focus() applied to it when the page is loaded?

Is there an existing way to do this same thing without needing to write:
Code:
<body onload="document.forms.addKey.keyword.focus();">

on all pages?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 16, 2013 8:01 pm    Post subject: Reply with quote

That would be managed in javascript, jQuery would be something like:

Code:
$(document).ready(function() {
    $('form:first *:input[type!=hidden]:first').focus();
});


Smarty won't be aware of javascript or forms on the page, it is just text to the template engine.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP