SunQuest
           HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 25th, 2000, 02:43 AM
CyberOsc CyberOsc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Indonesia
Posts: 87 CyberOsc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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 **

Reply With Quote
  #2  
Old August 25th, 2000, 07:51 AM
pieux pieux is offline
Seņor Member
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2000
Posts: 1,156 pieux User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 59 sec
Reputation Power: 9
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.

Reply With Quote
  #3  
Old August 28th, 2000, 12:34 AM
CyberOsc CyberOsc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Indonesia
Posts: 87 CyberOsc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9


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 **

Reply With Quote
  #4  
Old August 28th, 2000, 10:25 AM
pieux pieux is offline
Seņor Member
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2000
Posts: 1,156 pieux User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 59 sec
Reputation Power: 9
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]

Reply With Quote
  #5  
Old August 28th, 2000, 09:31 PM
CyberOsc CyberOsc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Indonesia
Posts: 87 CyberOsc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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 **

Reply With Quote
  #6  
Old August 29th, 2000, 08:29 AM
pieux pieux is offline
Seņor Member
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2000
Posts: 1,156 pieux User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 59 sec
Reputation Power: 9
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).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > checking the textarea value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway