Hi friends,
How do i ensure that my textarea value should always contain the word "india" in javascript?
Actually i want to validate the textarea so that the user should always the word "india" in that.
Please help me. Thanks in advance.
Hi friends,
How do i ensure that my textarea value should always contain the word "india" in javascript?
Actually i want to validate the textarea so that the user should always the word "india" in that.
Please help me. Thanks in advance.
You can use the blur
event which is invoked when the user removes focus from the textarea
.
<textarea onblur="return validate(this);"></textarea>
var reg = /\bindia\b/im;
function validate(textArea) {
// case-insensitive search for "india"
if (!reg.test(textArea.value)) {
alert("Where's India?");
}
}
do you mean when the page loads to have the word 'India' in your textarea and it can be written over? or do you want it there permanent?
<textarea onchange='if(this.value.indexOf("india") == -1) this.value = "";'></textarea>