473,804 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Field Set Focus?

Greetings,

I'm still something of a newbie to html/php/mysql.

I have a php/html form with several fields of type "input". If the user
enters improper data in a particular field and clicks the Submit button,
the php script has to trap it and return a javascript error message box
with an OK button. That part I've already got down.

But, you know how in Visual Basic you can set the focus on the offending
field on a form, so if the user gets a Message Box with an error message
and clicks OK, the form goes something like,

myForm!myField. SetFocus

Is there an equivalent way in php/html way do this?

Jul 17 '05 #1
5 28145
'bonehead wrote:
Greetings,

I'm still something of a newbie to html/php/mysql.

I have a php/html form with several fields of type "input". If the
user enters improper data in a particular field and clicks the Submit
button, the php script has to trap it and return a javascript error
message box with an OK button. That part I've already got down.

But, you know how in Visual Basic you can set the focus on the
offending field on a form, so if the user gets a Message Box with an
error message and clicks OK, the form goes something like,

myForm!myField. SetFocus

Is there an equivalent way in php/html way do this?


This is not a PHP issue... PHP is rendered totally server side, and has no
control over the client like that. You are looking for some sort of
client-side scripting - either way, it's not a PHP thing.
Jul 17 '05 #2
While the city slept, 'bonehead <se*********@he re.org> feverishly typed:
Greetings,

I'm still something of a newbie to html/php/mysql.

I have a php/html form with several fields of type "input". If the
user enters improper data in a particular field and clicks the Submit
button, the php script has to trap it and return a javascript error
message box with an OK button. That part I've already got down.

But, you know how in Visual Basic you can set the focus on the
offending field on a form, so if the user gets a Message Box with an
error message and clicks OK, the form goes something like,


As already stated, you need to use a client-side technology to *attempt
to*[1] set the focus, which is quite easy in Javascript (something along the
lines of document.yourFo rmName.yourFiel dName.focus();) . However, you have to
be careful, as the user may have started typing into other fields in the
form while the page is still loading, then when the page loads and your
chosen field gets focus, the user may not realise and continue typing -
unaware that they are now typing nonsense into the wrong field. I set up
this page: http://www.nigenet.org.uk/bits-n-bob...FocusTest.html a while
ago when this issue came up over in news:alt.html. It has 3 text fields, and
when the page is loaded it will set the focus to the first one, unless the
user has already started using any of the fields, in which case it doesn't
set the focus. The so-called "huge image to slow the loading process"
probably doesn't apply in this day of ever-spreading broadband usage - maybe
I should set up a special broadband version with the full size image on? ;-)

Anyway, take a look at the code and see if you can adapt it to your needs.
You can use PHP to write out the javascript to set the field, so it sets to
whichever is the offending field. Something along the lines of:

<?php
// Your form validation stuff here
$badfield = // set this up to be the name of the field you want to set the
focus to
?>

<script type="text/javascript">
<!-- Hide

// some javascript stuff here... see the source in my example page

<?
echo("document. yourFormName.$b adfield.focus() ;\n");
?>

// dunhidin -->
</script>

[1] This will only work if javascript is available to the end-user, and
enabled. The same goes for your javascript validation script, so always
validate on the server-side as well.

Hope that helps,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #3
I noticed that Message-ID: <c7************ @ID-112325.news.uni-berlin.de>
from nice.guy.nige contained the following:
Greetings,


Hi nige,

I'm beginning to worry about the links being forged between
uk.rec.humour and PHP...

--
black-dog

A dog does not care about the previous dogs in your life.
Jul 17 '05 #4
Thanks! This looks great...I'll try it.

nice.guy.nige wrote:
<?php
// Your form validation stuff here
$badfield = // set this up to be the name of the field you want to set the
focus to
?>

<script type="text/javascript">
<!-- Hide

// some javascript stuff here... see the source in my example page

<?
echo("document. yourFormName.$b adfield.focus() ;\n");
?>

// dunhidin -->
</script>


Jul 17 '05 #5
While the city slept, Geoff Berrow <bl******@ckdog .co.uk> feverishly typed:
I noticed that Message-ID:
<c7************ @ID-112325.news.uni-berlin.de> from nice.guy.nige
contained the following:
Greetings,


Hi nige,

I'm beginning to worry about the links being forged between
uk.rec.humour and PHP...


What's the difference between PHP? One of it's default settings is both the
same! ;-)

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3752
by: JJ | last post by:
Hi All, When someone selects a value in a select on a form I want to show the same form with another select with certain values depending on first select. How can I do this? Should I keep acouple of arrays loaded with the second selects values not to be shown till selected in first or what other means? Also how do you reload the current form to show maybe a nex field or select box?
2
14301
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish to put the focus back to the offending field. ( It works if a use an 'onblur' event but not an 'onchange' )
1
2824
by: Cooper | last post by:
Hello, i have a form with TEXT, SELECT etc, elements. Simple, i suppose two TEXT (name: T1 and T2). If a user insert a bad value, it display a error message and turn back at form. My problem is: I am in T1, i insert a bad value... is displayed a alert, i click on OK and prompt go in T2. Now, i want to do that if i am in T1 after that i click OK in alert window, the prompt turn in T1 and not go in T2. I hope that i have explained my...
6
4346
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web developers, but is relevant discussion. i'm not OT here unless someone thinks i'm trolling (which i'm not, obviously). then i'll disappear and never show my face again. :P
4
1832
by: Semi Head | last post by:
Hello folks, I'm looking for a script to validate a specific number value in a standard form input field. An example would be, if someone enters a number into a form input, I want the script to validate it and give an alert if that the number exceeds the set script value. Like if the script value is set for 3000 and the number 3002 is entered, I want an alert to pop and give a warning, BTW - This script must be generic enough to work...
15
4667
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
1
3371
by: tdmailbox | last post by:
Is there a vb command that can tell me if I have focus in the child or parent form? Basicly I have a search macro that needs me to have focus to any field in the parent form. If my focus is set on any field in the parent form it will search that field. However if I have focus set to a field in the child form it fails. What I want to do is set focus to field1 of the parent table but ONLY if focus is on a field in the child form. Is...
4
4192
by: GTi | last post by:
Is it possible to have a generic script that set the input focus on the first valid element in a document (not hidden or disabled) ? This script is at the end of a document, but don't work. <script type="text/javascript"> document.forms.elements.focus(); </script>
8
6704
by: M.L. | last post by:
Hello. I created a form using JS validation with the form tag as follows: <form name="form1" action="dynaform.php" method="post" onsubmit="return pvg_sub();"> The js validation script sends alerts when fields are not entered properly and it seems to work, except...when there are no errors, instead executing the php action script, I get a popup dialog box in IE6 asking if I want to download or run the php script. Can anyone tell me
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.