var val1=document.getElementById("text_1");
var but_val=document.getElementById("button_1");
var but_val2=document.getElementById("button_2");
var but_val3=document.getElementById("button_3");

function click()
{
alert("the value is " +val1.value);
}
but_val.onclick=click;
function array()
{
	var length=val1.value.length;
	alert("length is " +length);
	var newarr=new Array();
	for(var i=0;i<length;i++)
	{
		newarr[i]=val1.value[i];//this is the MAIN PART textbox value comes here in array supose value is 1234
		alert(newarr[i]);
	}
	var c=0;
	for(var j=0;j<length;j++)
	{
		//now i dont know how to to get sum of all numbers in value
	}
	alert("the sum is " +c);
}
but_val2.onclick=array;

To read value from an array...

// Let say newarr contains [1, 2, 3, 4]
var c=0
for (var j=0; j<newarr.length; j++) {
  c += newarr[j]  // add each value in newarr to c
}

// if all elements in newarr are integer, you will get 10
// if all elements in newarr are string, you will get 1234
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.