Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Form Validation


Message #1 by "Paul Cracknell" <paul.cracknell@b...> on Sat, 10 Nov 2001 19:51:50
Help



This is my second time of asking, I have been trying everything I can 

think of to solve the problem but getting nowhere.



The problem is that I am validating a single textbox on a form which is 

posted to a response page. The validation is "onClick" of a button

and is post does not take place if "Len = 0". all is well unless the user 

pushes the enter/carriage return key in which case the onClick validation 

is bypassed and rendered useless.



J House kindly offered a javascript solution that is capable of producing 

an alert but if you ack the OK with the enter key the response page 

continues to be returned.



Any suggestions would be very welcome



Paul C
Message #2 by "Pat Waddington" <paw@s...> on Sat, 10 Nov 2001 21:39:42 -0000
This is just a suggestion and I don't know if it would work because I

haven't tried it:)



You should be able to trap the pressing of the Return key by using an

OnKeyPress event handler. You should check to see if it was the Return key

that was pressed (using the 'which' property I think), and if it is return

False from the event handler.



This would cancel processing of the keystroke.



HTH

----- Original Message -----

From: "Paul Cracknell" <paul.cracknell@b...>

To: "ASP Databases" <asp_databases@p...>

Sent: Saturday, November 10, 2001 7:51 PM

Subject: [asp_databases] Form Validation





> Help

>

> This is my second time of asking, I have been trying everything I can

> think of to solve the problem but getting nowhere.

>

> The problem is that I am validating a single textbox on a form which is

> posted to a response page. The validation is "onClick" of a button

> and is post does not take place if "Len = 0". all is well unless the user

> pushes the enter/carriage return key in which case the onClick validation

> is bypassed and rendered useless.

>

> J House kindly offered a javascript solution that is capable of producing

> an alert but if you ack the OK with the enter key the response page

> continues to be returned.

>

> Any suggestions would be very welcome

>

> Paul C

>




$subst('Email.Unsub')

>

>

>





Message #3 by "Kim Iwan Hansen" <kimiwan@k...> on Sun, 11 Nov 2001 00:05:12 +0100
Hi Paul :)



If i understand you correctly, the problem is that the javascript that

validates the form isn't activated when the user submits the form WITHOUT

clicking on the submit button... if that's correct, my solution will work:



instead of trapping the onClick event for the button, you do onSubmit for

the form as follows (watch for wrapping):





<script language="javascript">

<!--

function checkForm(){

	var errMsg = '';

	var frm = document.theform



	if (frm.thename.value == '') errMsg += '\nMust fill in your name';



	if (errMsg != ''){ alert('Error!' + errMsg); }

	else { frm.submit(); }

}

//-->

</script>





<form name="theform" ... onSubmit="checkForm(); return false;">

<input type="text" name="thename" ...>

<input type="submit">

</form>







Hope you can use this and combine it with your own :)



-Kim





-----Original Message-----

From: Paul Cracknell [mailto:paul.cracknell@b...]

Sent: 10. november 2001 19:52

To: ASP Databases

Subject: [asp_databases] Form Validation





Help



This is my second time of asking, I have been trying everything I can

think of to solve the problem but getting nowhere.



The problem is that I am validating a single textbox on a form which is

posted to a response page. The validation is "onClick" of a button

and is post does not take place if "Len = 0". all is well unless the user

pushes the enter/carriage return key in which case the onClick validation

is bypassed and rendered useless.



J House kindly offered a javascript solution that is capable of producing

an alert but if you ack the OK with the enter key the response page

continues to be returned.



Any suggestions would be very welcome



Paul C






$subst('Email.Unsub')





Message #4 by Imar Spaanjaars <Imar@S...> on Sun, 11 Nov 2001 00:16:03 +0100
Hi there,



Move your validation from the onClick of the button to the event onSubmit 

of the form. Make sure you use the return statement, because otherwise the 

form still gets submitted.

Here is a working example of just a textbox and no submit button. If you 

press enter without entering a value, a dialog is presented and the form is 

not submitted.



<html>

<head>

    <script language="JavaScript" type="text/javascript">

    function submitForm()

    {

       if (document.forms(0).txtTest.value == '')

       {

          alert('Field required');

          return false;

       }

    }

</script>

</head>

<body>

    <form method="post" action="somePage.asp" onsubmit="return submitForm();">

       <input type="text" id="txtTest">

    </form>

</body>

</html>



HtH



Imar









At 07:51 PM 11/10/2001 +0000, you wrote:

>Help

>

>This is my second time of asking, I have been trying everything I can

>think of to solve the problem but getting nowhere.

>

>The problem is that I am validating a single textbox on a form which is

>posted to a response page. The validation is "onClick" of a button

>and is post does not take place if "Len = 0". all is well unless the user

>pushes the enter/carriage return key in which case the onClick validation

>is bypassed and rendered useless.

>

>J House kindly offered a javascript solution that is capable of producing

>an alert but if you ack the OK with the enter key the response page

>continues to be returned.

>

>Any suggestions would be very welcome

>

>Paul C

>








Message #5 by "Ken Schaefer" <ken@a...> on Mon, 12 Nov 2001 12:40:21 +1100
Paul,



Is this really the most appropriate list to be asking this question? Perhaps

that is why you are not getting much in the way of responses...



To be honest, I'm not sure what your question has to do with ASP, or

databases.



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Paul Cracknell" <paul.cracknell@b...>

Subject: [asp_databases] Form Validation





: Help

:

: This is my second time of asking, I have been trying everything I can

: think of to solve the problem but getting nowhere.

:

: The problem is that I am validating a single textbox on a form which is

: posted to a response page. The validation is "onClick" of a button

: and is post does not take place if "Len = 0". all is well unless the user

: pushes the enter/carriage return key in which case the onClick validation

: is bypassed and rendered useless.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Message #6 by "Dallas Martin" <dmartin@z...> on Sun, 11 Nov 2001 21:37:21 -0500
Paul

  Here's a snippet that may help you.

Dallas



<html>

<head>

<script language="JavaScript1.2">

<!--

function okay()

{

 var okay = true;

 var message = "";

 if (!confirm("Save your data?"))

 {

  return false;

 }

 if (document.forms[0].txtField.value == "")

 {

     okay = false;

     message = message + "Please enter a value in the text box.\n";

 }

 if (!okay)

 {

    alert(message)

 }

 return okay;

}

file://-->

</script>

</head>

<body>

<form name="thisform" method="post" action="sample.html">

<p>

Enter some text into the text box at the right: <input type="text"

name="txtField" size="10" value="">

</p>

<input type="submit" name="submit" value="Save Text" onclick="return

okay();">

</form>

</body>

</html>







----- Original Message -----

From: "Ken Schaefer" <ken@a...>

To: "ASP Databases" <asp_databases@p...>

Sent: Sunday, November 11, 2001 8:40 PM

Subject: [asp_databases] Re: Form Validation





> Paul,

>

> Is this really the most appropriate list to be asking this question?

Perhaps

> that is why you are not getting much in the way of responses...

>

> To be honest, I'm not sure what your question has to do with ASP, or

> databases.

>

> Cheers

> Ken

>

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> From: "Paul Cracknell" <paul.cracknell@b...>

> Subject: [asp_databases] Form Validation

>

>

> : Help

> :

> : This is my second time of asking, I have been trying everything I can

> : think of to solve the problem but getting nowhere.

> :

> : The problem is that I am validating a single textbox on a form which is

> : posted to a response page. The validation is "onClick" of a button

> : and is post does not take place if "Len = 0". all is well unless the

user

> : pushes the enter/carriage return key in which case the onClick

validation

> : is bypassed and rendered useless.

>

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>

>

>




$subst('Email.Unsub')

>



Message #7 by "Drew, Ron" <RDrew@B...> on Mon, 12 Nov 2001 08:15:15 -0500
Use onBlur instead of onClick.....onBlur="return CheckField()"

<script language="JavaScript">

<!-- 

function CheckField() {

  if (document.formmail.name.value == "")

   {

    alert("Please enter a value for the \"Name\" field.");

    document.formmail.name.focus();

    return (false);

   }

 alert(fname+" ..Thank you for completing the form.  Your Information will

be sent when you close this window.");

  window.history.go(-1);

}

//-->

</script>



-----Original Message-----

From: Paul Cracknell [mailto:paul.cracknell@b...] 

Sent: Saturday, November 10, 2001 2:52 PM

To: ASP Databases

Subject: [asp_databases] Form Validation





Help



This is my second time of asking, I have been trying everything I can 

think of to solve the problem but getting nowhere.



The problem is that I am validating a single textbox on a form which is 

posted to a response page. The validation is "onClick" of a button and is

post does not take place if "Len = 0". all is well unless the user 

pushes the enter/carriage return key in which case the onClick validation 

is bypassed and rendered useless.



J House kindly offered a javascript solution that is capable of producing 

an alert but if you ack the OK with the enter key the response page 

continues to be returned.



Any suggestions would be very welcome



Paul C

 

---

You are currently subscribed to asp_databases as: RDrew@B... To

unsubscribe send a blank email to $subst('Email.Unsub')

Message #8 by "Drew, Ron" <RDrew@B...> on Mon, 12 Nov 2001 08:23:18 -0500
I agree with Imar.   I just sent the onBlur.  If you want to do this at a

field level, take the button out and use onBlur.  If you want to test all

fields at the end use the onSubmit.  Just remember to use the return as

mentioned.



-----Original Message-----

From: Imar Spaanjaars [mailto:Imar@S...] 

Sent: Saturday, November 10, 2001 6:16 PM

To: ASP Databases

Subject: [asp_databases] Re: Form Validation





Hi there,



Move your validation from the onClick of the button to the event onSubmit 

of the form. Make sure you use the return statement, because otherwise the 

form still gets submitted.

Here is a working example of just a textbox and no submit button. If you 

press enter without entering a value, a dialog is presented and the form is 

not submitted.



<html>

<head>

    <script language="JavaScript" type="text/javascript">

    function submitForm()

    {

       if (document.forms(0).txtTest.value == '')

       {

          alert('Field required');

          return false;

       }

    }

</script>

</head>

<body>

    <form method="post" action="somePage.asp" onsubmit="return

submitForm();">

       <input type="text" id="txtTest">

    </form>

</body>

</html>



HtH



Imar









At 07:51 PM 11/10/2001 +0000, you wrote:

>Help

>

>This is my second time of asking, I have been trying everything I can 

>think of to solve the problem but getting nowhere.

>

>The problem is that I am validating a single textbox on a form which is 

>posted to a response page. The validation is "onClick" of a button and 

>is post does not take place if "Len = 0". all is well unless the user 

>pushes the enter/carriage return key in which case the onClick 

>validation is bypassed and rendered useless.

>

>J House kindly offered a javascript solution that is capable of 

>producing an alert but if you ack the OK with the enter key the 

>response page continues to be returned.

>

>Any suggestions would be very welcome

>

>Paul C

>




>$subst('Email.Unsub')







 

---

You are currently subscribed to asp_databases as: RDrew@B... To

unsubscribe send a blank email to $subst('Email.Unsub')

Message #9 by "Robert Segarra" <robert_segarra@h...> on Tue, 13 Nov 2001 12:00:40 -0600
Have you tried to do validation on the submit of the form instead of the

click of the button?



----- Original Message -----

From: "Paul Cracknell" <paul.cracknell@b...>

To: "ASP Databases" <asp_databases@p...>

Sent: Saturday, November 10, 2001 7:51 PM

Subject: [asp_databases] Form Validation





> Help

>

> This is my second time of asking, I have been trying everything I can

> think of to solve the problem but getting nowhere.

>

> The problem is that I am validating a single textbox on a form which is

> posted to a response page. The validation is "onClick" of a button

> and is post does not take place if "Len = 0". all is well unless the user

> pushes the enter/carriage return key in which case the onClick validation

> is bypassed and rendered useless.

>

> J House kindly offered a javascript solution that is capable of producing

> an alert but if you ack the OK with the enter key the response page

> continues to be returned.

>

> Any suggestions would be very welcome

>

> Paul C

>



robert_segarra@h...


$subst('Email.Unsub')

>

>


  Return to Index