#1 (permalink)  
Old 09-27-2005, 08:32 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
Store Form Focus As Variable?

Is it possible to store the current focus of a form in a variable (preferably PHP, but I am open to using JavaScript if necessary), so that, when the page reloads, the cursor will automatically be placed in the next form field?

I am working with a semi-complicated reporting application I wrote in PHP, using SQL. When the user chooses certain information from form fields, the form is submitted in order to fill in other fields properly and reloads the page with the new information in the form. I would like to have the focus set automatically on the next form field when the page reloads.

In other words, let's say I have 5 form fields in my form. When a user selects a month from form field 2, the form is submitted, reloading the page, and fills in form field 3 (which is a select box) with the number of days in that month, so that the user won't select an invalid option. I would like to automatically set the focus, on the event that form field 2 changes and causes the page to submit, to form field 3. I am assuming that the easiest way to do this is to figure out which form field the user last interacted with, and then add 1 to that number and set that as the focus when the page loads again.

Any suggestions? Any resources for me to look at? I've tried Googling, but I'm not 100% sure what to Google for in this case. I've never even seen a form that does this, personally, so I don't even have any examples to look at.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote

  #2 (permalink)  
Old 09-30-2005, 10:41 AM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
No idea, but do something like this:

PHP Code:
<script language="JavaScript">
<?php
if ($_POST['field3'] == 'foo')
{
?>
document.form.field4.focus();
<?php
}
elseif (...)
{
...
}
else
{
...
}
?>
</script>
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web form data into a database dmitcha Programming and Scripting 1 07-05-2005 06:00 PM
Avoiding duplicated form submissions stanton Programming and Scripting 2 05-13-2005 08:28 AM
dynamically changing form names theninjasquad Programming and Scripting 1 05-02-2005 10:48 PM
Really lame Javascript form submission problem pillsbur Programming and Scripting 1 04-19-2005 11:13 AM
Using a variable as defaut value in form field dilbertza2 Programming and Scripting 1 04-17-2005 12:03 PM


All times are GMT -5. The time now is 04:23 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter