I have to paste the data in HTML input text fields in the following format from MS excel or same type of sheets:
123456 12 this
234567 3 before blank
111111 3
222222 3 after blank
I copied the data from MS Excel which contain the single tab between 12
and this
and so on.. I have tried to implement it but didn't work for me. The above data will be pasted into a text area and it save into a another JavaScript variable into the following format:
<row dc= '" + arr[0] + "' al='" + arr[1] + "' msg='" + arr[2] + "' />
Where arr[0]
is 123456
, and arr[1]
is 12
and arr[3]
is this
and so on by appending the value.
I have to paste the data in HTML input text fields in the following format from MS excel or same type of sheets:
123456 12 this
234567 3 before blank
111111 3
222222 3 after blank
I copied the data from MS Excel which contain the single tab between 12
and this
and so on.. I have tried to implement it but didn't work for me. The above data will be pasted into a text area and it save into a another JavaScript variable into the following format:
<row dc= '" + arr[0] + "' al='" + arr[1] + "' msg='" + arr[2] + "' />
Where arr[0]
is 123456
, and arr[1]
is 12
and arr[3]
is this
and so on by appending the value.
1 Answer
Reset to default 3var str=document.getElementById("myTextarea").value
var t=str.split("\n");
for (var i=0;i<t.length;i++)
{
var arr=t[i].split("\t");
document.write("'<row dc= '" + arr[0] + "' al='" + arr[1] + "' msg='" + arr[2] + "' />'")
}
Working Sample:-
<!DOCTYPE html>
<html>
<body>
<script>
function submit_a () {
var str=document.getElementById("allocationstatus").value
//str=str.replace('\t','	');
//document.getElementById("allocationstatus").value=str;
var t=str.split("\n");
var s='';
for (var i=0;i<t.length;i++)
{
var arr=t[i].split("\t");
s ="'<row dc= '" + arr[0] + "' al='" + arr[1] + "' msg='" + arr[2] + "' />'";
alert(arr.length);
for (var j=0;j<arr.length;j++)
{
//alert(arr[j]);
}
//document.write(s);
}
}
</script>
<textarea rows = "5" cols = "80" id = "allocationstatus" >stat	do	one
stat1	do1	one1
stat2	do1	one1</textarea>
<input type = "button" onclick = "submit_a();"/>
</body>
</html>