|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I just wondering how to check the content of the textarea.
I have a form which will be posted and proceed in a PHP script, but before it's submitted, I want to check the content of the textarea ( in JavaScript function ) If it's empty then return false and do not continue to the process page. Here's my coding : <script> function validate(form) { if (!form.comment.value) { alert ("Fill it"); form.comment.focus(); return false; } } </script> <form action="process.php3" method="post" onSubmit="return validate(this)"> <textarea name="comment" cols=40 rows=5> <input type="submit"> </form> But the script doesn't work !! It always go to the process page whether the textarea is empty or not. Anyone help me please !!! See ya ------------------ ** It's the world of Oscario ** |
|
#2
|
|||
|
|||
|
You need to also add (seperated by a ';') return=false to make the submit part of the form break. Then, in your JavaScript, you submit the form.
|
|
#3
|
|||
|
|||
I've try to add ; return false; but it still doesn't work !! Sometimes it works and sometimes not !! Any other solution please ?? ------------------ CyberOsc sphmjf_oscario@gurlmail.com ** It's the world of Oscario ** |
|
#4
|
|||
|
|||
|
Rather than spend time to debug your code, here is an example that I have verified works (I just recently created the site):
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><SCRIPT LANGUAGE="JavaScript"> function checkFields() { em = "The following field(s) cannot be blank: " if (document.formName.fieldOne.value == "") em = em + "n * Text1"; if (document.formName.fieldTwo.value == "") em = em + "n * Text2"; if (em.indexOf('*') > 0) { alert(em); return false; } } </SCRIPT> <FORM NAME="formName" METHOD="post" ACTION="process-file.php" onSubmit="return checkFields();">[/code] |
|
#5
|
|||
|
|||
|
pieux,...
I've tried your code above. It does work for <input type=text> but for <textarea> </textarea> , it doesn't work !! pieux.. would you please try it with <textarea>. And please tell me if you had a solution. Or anybody else have a solution for me ?? Thx !! See ya ------------------ CyberOsc sphmjf_oscario@gurlmail.com ** It's the world of Oscario ** |
|
#6
|
|||
|
|||
|
It worked for me with a TEXTAREA. Make sure you are giving the TEXTAREA a name. <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><SCRIPT LANGUAGE="JavaScript">
function checkFields() { em = "The following field(s) cannot be blank: " if (document.formName.fieldOne.value == "") em = em + "n * Text1"; if (document.formName.fieldTwo.value == "") em = em + "n * Text2"; if (em.indexOf('*') > 0) { alert(em); return false; } } </SCRIPT> <FORM NAME="formName" METHOD="post" ACTION="process-file.php" onSubmit="return checkFields();"> <INPUT TYPE="TEXT" NAME="fieldOne"> <TEXTAREA NAME="fieldTwo"></TEXTAREA> <INPUT TYPE="Submit"> </FORM>[/code] I've have tested it in Netscape 4.7 and IE 5.0. [This message has been edited by pieux (edited August 29, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > checking the textarea value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|