0

guys this is my text box
a. <input type="text" id="val" value="1,23|20,70|40,100|64,120" >

my question is how can i output something like this.?
var chart = [[1,23 ],[20,70],[40,100],[64,120]];

any idea? your help would be greatly appreciated thanx in advance.

2
Contributors
1
Reply
11
Views
4 Years
Discussion Span
Last Post by minitauros
0

Well, reading your post I'm assuming this is your problem:

In Javascript you have an array with values (var chart in your example), which you want to be converted to a string and then to be set as the value of a specific input checkbox. This can be achieved as follows:

var array = [[1,23 ],[20,70],[40,100],[64,120]];

for(var i = 0; i < array.length; i++)
{
    var record = array[i].join();
    array[i] = record;
}

var string = array.join('|');
// String now has the value "1,23|20,70|40,100|64,120"

To set your input's value to be this value, you can use one of the following snippets, depending on if you're using jQuery or not:

// Non jQuery:
document.getElementById('val').value = string;

// jQuery:
$('input#val').val(string);

Edited by minitauros

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.