0
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;
2
Contributors
1
Reply
6
Views
5 Years
Discussion Span
Last Post by Taywin
0

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

Edited by Taywin: n/a

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.