View Full Version : Validation for TextArea
CoraLover
03-14-2003, 02:52 PM
Hi, how do i validate that the user has entered nothing in a TEXTAREA??
ACJavascript
03-14-2003, 02:58 PM
Try this
<script language="javascript">
function validate(){
if(document.text1.info.value==""){
alert("Sorry but you didn't put anything in!")
}else{
//DO what you want it they did
}
}
</script>
---------
<form name="text1">
<textarea name="info" rows=8 cols=50 wrap="virtual">
</textarea>
</form>
I didn't test it so sorry if there are errors hehe :D
Hope this helps
requestcode
03-14-2003, 03:24 PM
Or:
function validate(){
if(document.text1.info.value.length==0){
alert("Sorry but you didn't put anything in!")
document.text1.info.focus()
}else{
//DO what you want it they did
}
}
CoraLover
03-14-2003, 03:44 PM
Thanks to ACJavascript and requestcode! It works now! But i've actually tried the methods u all mentioned earlier on, on some other PCs, but it didn't work. So i'm wondering, is it that certain version of IE doesn't support it?? Impossible, right?
arnyinc
03-14-2003, 08:17 PM
Here are some small edits to the two previous functions.
<html>
<head>
<script language="javascript">
function validate(myform){
if(myform.info.value==""){
alert("Sorry but you didn't put anything in!")
return false;
}
else
return true;
}
</script>
</head>
<body>
<form name="text1" onsubmit="return validate(this)">
<textarea name="info" rows=8 cols=50 wrap="virtual"></textarea>
<input type="submit">
</form>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.