So run the loop in reverse order:
Code:
var inputArray = [];
var inputs = document.getElementsByTagName('input');
for ( var i = inputs.length - 1; i >= 0; --i )
{
var input = inputs[i];
if (input.type == 'text') { inputArray.push(input); }
}
inputArray[0].value = phone1;
You know, if you really only want to find the last <input> and don't need all the other elements, you could just do this:
Code:
var inputs = document.getElementsByTagName('input');
for ( var i = inputs.length - 1; i >= 0; --i )
{
if ( inputs[i].type == "text" )
{
inputs[i].value = phone1;
break;
}
}