irfan harun irfan harun - 1 year ago 68
Javascript Question

grabbing multiple data from textbox into textbox using javascript

My code works well for a single-lined input into the textbox. For example:


But what I want is, to grab the name and class when I input data into the textbox. Something like this:


class:8th grade

function myFunction()
var x = document.getElementById("tarea");
document.getElementById("name").value = x.value.substring(5);

And in the HTML section, I have this:

<textarea rows="4" cols="50" id="tarea" onblur="myFunction()"></textarea>

name: <input type="text" id="name"></br>
class: <input type="text" id="class">

Answer Source

you should split your textarea based on newlines. something like

function myFunction()

var x = document.getElementById("tarea"),
    nameInput = document.getElementById('name'),
    classInput = document.getElementById('class');

var lines = x.value.split('\n');
var name = lines[0].substring(5);
var grade = lines[1].substring(6);

nameInput.value = name;
classInput.value = grade;   



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download