473,756 Members | 8,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript form control element validation

I have a form on an HTML page with the usual user name, email etc. I
want to be able to display a popup window (callout?) when a text input
control element is clicked.

For example, for the form:

<form action="somethi ng.php" method="post">
<label for="uname">Use r Name</label>
<input type="text" id="uname"/>
<input type="image" src="go.gif"/>
</form>

When the user clicks in the user name fields, I want to display a
callout (or popup window), with the text:

"The username must be at least 8 character long"

does anyone know how to do this?
Jun 27 '08 #1
4 1981
On May 8, 6:44*am, Ronald Raygun <inva...@domain .comwrote:
I have a form on an HTML page with the usual user name, email etc. I
want to be able to display a popup window (callout?) when a text input
control element is clicked.

For example, for the form:

<form action="somethi ng.php" method="post">
* *<label for="uname">Use r Name</label>
* *<input type="text" id="uname"/>
* *<input type="image" src="go.gif"/>
</form>

When the user clicks in the user name fields, I want to display a
callout (or popup window), with the text:

"The username must be at least 8 character long"

does anyone know how to do this?
To answer your question:

<input type="text" id="uname" onfocus="alert( 'The username must be at
least 8 character long');"/>

I think you will find that this gets a bit tedious for the user. I
would recommend just telling them right on the screen. Maybe something
like:

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif"/></td>
</tr>
</table>
</form>

Then, of course, you would perform some validation that 8 characters
were actually entered before submitting. Maybe something like this:

<script type="text/javascript">

function checkDigits() {
var uname = document.getEle mentById("uname ").value;
if (uname.length == 8) {
return true;
}
else {

}
}

</script>
...

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif" onclick="return
checkDigits();"/></td>
</tr>
</table>
</form>

HTH...
Jun 27 '08 #2
On May 8, 7:38*am, Tom Cole <tco...@gmail.c omwrote:
On May 8, 6:44*am, Ronald Raygun <inva...@domain .comwrote:


I have a form on an HTML page with the usual user name, email etc. I
want to be able to display a popup window (callout?) when a text input
control element is clicked.
For example, for the form:
<form action="somethi ng.php" method="post">
* *<label for="uname">Use r Name</label>
* *<input type="text" id="uname"/>
* *<input type="image" src="go.gif"/>
</form>
When the user clicks in the user name fields, I want to display a
callout (or popup window), with the text:
"The username must be at least 8 character long"
does anyone know how to do this?

To answer your question:

<input type="text" id="uname" onfocus="alert( 'The username must be at
least 8 character long');"/>

I think you will find that this gets a bit tedious for the user. I
would recommend just telling them right on the screen. Maybe something
like:

<form action="somethi ng.php" method="post">
*<table>
* * * * <tr>
* * * * * * * * <td><label for="uname">Use r Name</label></td>
* * * * * * * * <td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
* * * * * * * * <td><input type="image" src="go.gif"/></td>
* * * * </tr>
*</table>
</form>

Then, of course, you would perform some validation that 8 characters
were actually entered before submitting. Maybe something like this:

<script type="text/javascript">

function checkDigits() {
* * * * var uname = document.getEle mentById("uname ").value;
* * * * *if (uname.length == 8) {
* * * * * * *return true;
* * * * *}
* * * * *else {

* * * * *}

}

</script>
...

<form action="somethi ng.php" method="post">
*<table>
* * * * <tr>
* * * * * * * * <td><label for="uname">Use r Name</label></td>
* * * * * * * * <td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
* * * * * * * * <td><input type="image" src="go.gif" onclick="return
checkDigits();"/></td>
* * * * </tr>
*</table>
</form>

HTH...- Hide quoted text -

- Show quoted text -
Sorry, using Google Groups sucks beyond all belief...

<script type="text/javascript">

function checkDigits() {
var uname = document.getEle mentById("uname ").value;
if (uname.length == 8) {
return true;
}
else {
alert("Must be 8 characters.");
return false;
}

}

</script>
...

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label
style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif" onclick="return
checkDigits();"/></td>
</tr>
</table>
</form>

So now the alert only pops up when the don't follow instructions :)

HTH
Jun 27 '08 #3


Tom Cole wrote:
On May 8, 7:38 am, Tom Cole <tco...@gmail.c omwrote:
>>On May 8, 6:44 am, Ronald Raygun <inva...@domain .comwrote:

>>>I have a form on an HTML page with the usual user name, email etc. I
want to be able to display a popup window (callout?) when a text input
control element is clicked.
>>>For example, for the form:
>>><form action="somethi ng.php" method="post">
<label for="uname">Use r Name</label>
<input type="text" id="uname"/>
<input type="image" src="go.gif"/>
</form>
>>>When the user clicks in the user name fields, I want to display a
callout (or popup window), with the text:
>>>"The username must be at least 8 character long"
>>>does anyone know how to do this?

To answer your question:

<input type="text" id="uname" onfocus="alert( 'The username must be at
least 8 character long');"/>

I think you will find that this gets a bit tedious for the user. I
would recommend just telling them right on the screen. Maybe something
like:

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif"/></td>
</tr>
</table>
</form>

Then, of course, you would perform some validation that 8 characters
were actually entered before submitting. Maybe something like this:

<script type="text/javascript">

function checkDigits() {
var uname = document.getEle mentById("uname ").value;
if (uname.length == 8) {
return true;
}
else {

}

}

</script>
...

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif" onclick="return
checkDigits() ;"/></td>
</tr>
</table>
</form>

HTH...- Hide quoted text -

- Show quoted text -


Sorry, using Google Groups sucks beyond all belief...

<script type="text/javascript">

function checkDigits() {
var uname = document.getEle mentById("uname ").value;
if (uname.length == 8) {
return true;
}
else {
alert("Must be 8 characters.");
return false;
}

}

</script>
...

<form action="somethi ng.php" method="post">
<table>
<tr>
<td><label for="uname">Use r Name</label></td>
<td><input type="text" id="uname"/><br><label
style="font-size:
8pt;">Must be 8 characters</label></td>
<td><input type="image" src="go.gif" onclick="return
checkDigits();"/></td>
</tr>
</table>
</form>

So now the alert only pops up when the don't follow instructions :)

HTH

Hi Tom, thanks for your response. I realized that I probably did not
state my question correctly/clearly. The behaviour I want is different
from that which you described. For one, I want to avoid using alert
boxes (at least in this scenario) - as I agree with you that they can be
very disuptive.

The behaviour I want, is to display a "hint" (like the kind you get when
you hover over a Microsoft Excel cell that has comments). So that when a
user clicks in the username cell, they have a "hint" that gives them
further info about the field, along with the opton to close the "hint".

A crude drawing of the kind of "hint" I want to display is shown below:

(--------------------------)
( Blah, blah, blah ... )
( ... )
( _______________ _______X )
\/

Where the X allows them to close the "hint" being displayed

HTH
Jun 27 '08 #4
On May 8, 7:57*am, Ronald Raygun <inva...@domain .comwrote:
Tom Cole wrote:
On May 8, 7:38 am, Tom Cole <tco...@gmail.c omwrote:
>On May 8, 6:44 am, Ronald Raygun <inva...@domain .comwrote:
>>I have a form on an HTML page with the usual user name, email etc. I
want to be able to display a popup window (callout?) when a text input
control element is clicked.
>>For example, for the form:
>><form action="somethi ng.php" method="post">
* <label for="uname">Use r Name</label>
* <input type="text" id="uname"/>
* <input type="image" src="go.gif"/>
</form>
>>When the user clicks in the user name fields, I want to display a
callout (or popup window), with the text:
>>"The username must be at least 8 character long"
>>does anyone know how to do this?
>To answer your question:
><input type="text" id="uname" onfocus="alert( 'The username must beat
least 8 character long');"/>
>I think you will find that this gets a bit tedious for the user. I
would recommend just telling them right on the screen. Maybe something
like:
><form action="somethi ng.php" method="post">
<table>
* * * *<tr>
* * * * * * * *<td><label for="uname">Use r Name</label></td>
* * * * * * * *<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
* * * * * * * *<td><input type="image" src="go.gif"/></td>
* * * *</tr>
</table>
</form>
>Then, of course, you would perform some validation that 8 characters
were actually entered before submitting. Maybe something like this:
><script type="text/javascript">
>function checkDigits() {
* * * *var uname = document.getEle mentById("uname ").value;
* * * * if (uname.length == 8) {
* * * * * * return true;
* * * * }
* * * * else {
* * * * }
>}
></script>
...
><form action="somethi ng.php" method="post">
<table>
* * * *<tr>
* * * * * * * *<td><label for="uname">Use r Name</label></td>
* * * * * * * *<td><input type="text" id="uname"/><br><label style="font-size:
8pt;">Must be 8 characters</label></td>
* * * * * * * *<td><input type="image" src="go.gif"onc lick="return
checkDigits(); "/></td>
* * * *</tr>
</table>
</form>
>HTH...- Hide quoted text -
>- Show quoted text -
Sorry, using Google Groups sucks beyond all belief...
*<script type="text/javascript">
*function checkDigits() {
* * * * *var uname = document.getEle mentById("uname ").value;
* * * * * if (uname.length == 8) {
* * * * * * * return true;
* * * * * }
* * * * * else {
* * * * * * * alert("Must be 8 characters.");
* * * * * * * return false;
* * * * * }
*}
*</script>
*...
*<form action="somethi ng.php" method="post">
* <table>
* * * * *<tr>
* * * * * * * * *<td><label for="uname">Use r Name</label></td>
* * * * * * * * *<td><input type="text" id="uname"/><br><label
style="font-size:
*8pt;">Must be 8 characters</label></td>
* * * * * * * * *<td><input type="image" src="go.gif" onclick="return
*checkDigits(); "/></td>
* * * * *</tr>
* </table>
</form>
So now the alert only pops up when the don't follow instructions :)
HTH

Hi Tom, thanks for your response. I realized that I probably did not
state my question correctly/clearly. The behaviour I want is different
from that which you described. For one, I want to avoid using alert
boxes (at least in this scenario) - as I agree with you that they can be
very disuptive.

The behaviour I want, is to display a "hint" (like the kind you get when
you hover over a Microsoft Excel cell that has comments). So that when a
user clicks in the username cell, they have a "hint" that gives them
further info about the field, along with the opton to close the "hint".

A crude drawing of the kind of "hint" I want to display is shown below:

(--------------------------)
( Blah, blah, blah ... * * )
( ... * * * * * * * * * * *)
( *______________ ________X )
* \/

Where the X allows them to close the "hint" being displayed

HTH- Hide quoted text -

- Show quoted text -
I'm not sure I see the distinction between this and an alert box. They
both serve the same purpose, they make the user deal with a window
that they otherwis would not have to. If it's not the first time
they've been there, then they know this already, why make them search
for and click a button on a window (whether it's an alert box or a
pretty "comic book" styled window)? I personally feel that just
placing the statement unobtrusively within the form is a more user
friendly approach.

If this is the route you prefer, you could easily create a hidden div
with a transparent background and use your hint graphic as the
background. Then simply place it where you want it relative to input
field (style.top & style.left) and make id visible.

There are several threads here about just this sort of thing.

HTH.
Jun 27 '08 #5

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

Similar topics

72
5224
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to complete in connection with attendance at a seminar. After spending more than 15 minutes on it, I clicked on the submit button - and nothing happened. Looking round the pages on Javascript form validation that Google produced for me (well,...
5
2692
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
2
1459
by: GIMME | last post by:
Background ... I've created a web application that allows a user to create an HTML application from IE. The application itself creates an XML representation of a XHTML form. The XHTML representation can be saved as a string and recreated. (The application also has a crude workflow aspect - so XMHTML forms can be created and assigned a workflow. Forget I said anything about
1
7782
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one checkbox is checked in the CheckBoxList control. Everything works fine for the server-side validation. However, we're having difficulties with writing a JavaScript function to perform the same validation on the client-side.
8
3674
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
27
4753
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
0
9287
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
9886
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
9857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7259
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
5155
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
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
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.