<input type="text" name="somename" value="somevalue1" />
<input type="text" name="somename" value="somevalue2" />
<input type="text" name="somename" value="somevalue3" />
<script type="text/javascript">
var x = document.getElementByName('somename');
// document.getElementByName() returns an array where
//x[0].value == "somevalue1";
//x[1].value == "somevalue2"
</script>
Note: getElementByName() only works for form elemnts if you need other elements a workaround would be to use var element = getElementByTagName() and assign a class to each element then you could look for that class using if element[index].className == "somename".
<input type="text" name="somename" value="somevalue2" />
<input type="text" name="somename" value="somevalue3" />
<script type="text/javascript">
var x = document.getElementByName('somename');
// document.getElementByName() returns an array where
//x[0].value == "somevalue1";
//x[1].value == "somevalue2"
</script>
Note: getElementByName() only works for form elemnts if you need other elements a workaround would be to use var element = getElementByTagName() and assign a class to each element then you could look for that class using if element[index].className == "somename".
Comments