473,504 Members | 13,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prompt and form

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 problem. Someone, help me about it?
Thanks you, Cooper.
Jul 20 '05 #1
1 2803
I think the regular expression test will treat an empty field the sama aws
an invalid field and reject it.

If you want the field to be allowed if null, byt check the syntax if it is
not null, try:

var FieldObject=FormObject.elements['fieldname']

// check to see if form field is empty, if *not* check syntax of form field
if(FieldObject.value!='')
{
if(!/^^[0-9a-zA-Z\s\,\/\-\.]+$?.test(FieldObject.value)
{
// invalid text in field
alert(str_error_01a + 'fieldname' + str_error_01b);
FieldObject.focus();
return false;
}
}

"Cooper" <co****@blueware.it> wrote in message
news:Wl********************@news2.tin.it...
"Richard Hockey" <ri***********@dsl.pipex.com> ha scritto nel messaggio
news:3f*********************@news.dial.pipex.com.. .
I think you are looking for the javascript focus() method, which sets the currently active form element.

<script type="text/javascript>
function Validate()
{
var FormObject=document.forms['myform'];
var T1Object=FormObject.elements['text1'];
var T2Object=FormObject.elements['text2'];

if(T1Object.value=='')
{
// display alert
alert('You have not entered any text in field 1. Please enter some now.'); // set focus on invalid field
T1Object.focus();
// go back to from WITHOUT submitting
return false;
}

if(T2Object.value=='')
{
alert('You have not entered any text in field 1. Please enter some now.'); T2Object.focus();
return false;
}

// all fields validated, submit form
return true;
}
</script>

<form name="myform" action=blah.php" method ="post" onSubmit="return
Validate();">
<input type="text" name="text1">
<input type="text" name="text2">
<input type="submit" value="Submit form">
</form>

Ok thanks you, but i have a problem now, if in a text i want to accept

also '' okay, i remove (es: T1Object.value=='' ) but in this case, if i have:

...........
campo00 = document.forms['form1'].elements[formField[0]];
if (!(/^[0-9a-zA-Z\s\,\/\-\.]+$/).test(campo00.value)) {
alert(str_error_01a + formField[0] + str_error_01b);
campo00.focus();
return false;
}
.............

it not accept a '' text null, what i fix it? is probably that error is in
regular expression, what is correct regular expression? Thanks you,
Cooper.

Jul 20 '05 #2

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

Similar topics

13
5303
by: JSE | last post by:
Hello everyone. here's what we have in an html file. <form ..... <input type=button name="comment" onclick=" prompt('enter comment',' ' )" > Is there anyway to get the value...
0
834
by: Laura Zeafla via .NET 247 | last post by:
I used the .NET forms application wizard. From the form youclick a button and it calls a C++ function through its dll. This function is supposed to pop-up a command prompt window. Something about...
0
1501
by: Laura Zeafla via .NET 247 | last post by:
I have an application I wrote using the Windows Form Application(.NET) wizard. Pressing a button calls a function in a dllwritten in Visual C++. This function is supposed to cause acommand prompt...
7
19258
by: Petesman | last post by:
I am trying to make a prompt that will ask the user for some input... If I just use var input = prompt("dafa") everything works fine but the box is put in the top left corner of the window. I need...
3
7876
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt for the 'rename' function, and a javascript alert...
3
5509
by: rsbutterfly16 | last post by:
hi all, I have a front end access database (mdb) with a sql server backend for my tables. I have an form in which I have created a store procedure in sql server, and i have a form created and also...
4
2269
by: Geoff Cox | last post by:
Hello, Very odd this? I have a form which has <input name="Submit" type="Submit" value="Click to send _ when finished" onclick="getName()"> and
5
3899
by: hcross | last post by:
This project is a web based html and Javascript site. I am working on mac at the moment. This script works except for attempting to open new window once complete. As you can see, i am new to...
4
7772
by: ARC | last post by:
Hello all, I didn't use to have this problem in Access 97, but in 2007 (and maybe other versions of access after 97), if you have a form that has a subform, and you click the close button, you...
1
2661
by: ramprakashjava | last post by:
hi , i hav this error while running this customerDetails.jsp <html:html> <head> <html:base/> </head> <body> <html:errors/> <html:form...
0
7213
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,...
0
7298
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,...
1
7017
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...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3187
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
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 ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
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...

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.