Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: open

Message Too Old, No Replies

getElementById('form') to get form items

     
7:04 pm on Aug 31, 2006 (gmt 0)

10+ Year Member



is it possible to getElementById('form') then get form inputs? Looking for an example for a dynamic form with a dynamic number of form inputs?

Thanks

7:20 pm on Aug 31, 2006 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month




<form id="myForm" action="">
<div>
<input name="foo">
<input name="bar">
<input name="xyz">
</div>
</form>
<script type="text/javascript">
function getFormItems()
{
if(!document.getElementById ) return;
var f = document.getElementById( 'myForm' );
// Step through the form elements
for( var i = 0; i < f.elements.length; i++ )
{
alert( f.elements[i].name );
}
}
getFormItems();
</script>

Hope that helps.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month