Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  128] [ 3]  / answers: 1 / hits: 20871  / 12 Years ago, tue, january 22, 2013, 12:00:00

Can anyone please tell me what the problem is with this code:



function c(id)
{
var empty = document.getElementById(id);
if(empty.length<1)
{
window.alert (This field cant be left empty);
return true;
}
else
{
return false;
}

}


This is my html code:



<textarea rows=3 cols=80 id=ta1 onChange=c('ta1');></textarea>

More From » html

 Answers
42

The value property of the textarea should be checked to determine if it is empty.



   var content = document.getElementById(id).value;

if(content.length<1)
{
window.alert (This field cant be left empty);
return true;
}
else
{
return false;
}


Working Example: http://jsfiddle.net/35DFR/2/


[#80717] Sunday, January 20, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;