Reputation: 109
I have created web application and textbox as a textarea. I am using javascript for validation. When I enter value in text box so it should be number not alphabet I have use textmode is multiple line.
My problem is that how I get multiple value from textbox and store in array in javascript and check each value is number or not. I am using the web form. Please help me.
Upvotes: 1
Views: 2143
Reputation: 187030
You can get the value from a textarea like
var txtvalue = document.getElementById("txtareaid").value
and if are using a separator then something like
var txtvaluearray = document.getElementById("txtareaid").value.split(';')
will get you all the values in an array if the seperator is ;
Edit
As per your update you can use \n
as the separator and as pointed by @Sohnee you can do the validation.
Upvotes: 1
Reputation: 250882
This is a starter for ten.
var textValues = document.getElementById("mytextarea").value.split("\n");
for (var i = 0; i < textValues.length; i++) {
if (isNaN(textValues[i])) {
alert(textValues[i] + " is not a number.";
}
}
Upvotes: 0
Reputation: 1384
As addition to rahul:
If you want the values in the textarea seperated by line, you can use \r\n as the splitter.
Upvotes: 0