jug Posted July 10, 2009 Share Posted July 10, 2009 Hi, I need to be able to separate all form inputs into 3 groups, normal single inputs, radio buttons and checkbox groups. Obviously compiling the first 2 groups are easy but im struggling with checkbox groups. The only information i wish to feed to the function is the form name and 3 arrays need to be returned with the forms inputs split into the groups i mentioned above. var formName = "searchform"; var formElements = document.getElementById(formName).elements; //from the form name compile 3 arrays of inputs name depending on type var singleElements = new Array(); //single inputs (ie text, password, textarea, single checkboxes) var radioElements = new Array(); //radio buttons var checkElements = new Array(); //checkbox groups I hope i have explained the issue well enough. Any other questions feel free to ask. Thanks in advance. jug Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 11, 2009 Share Posted July 11, 2009 You should just name your checkbox "groups" with the same name that will be treated as an array by the processing page. You can then also reference these "groups" within the javascript. Example: <input type="checkbox" name-"somefield[]" value="1"> <input type="checkbox" name-"somefield[]" value="2"> <input type="checkbox" name-"somefield[]" value="3"> These can be referenced via javascript like this: var formName = "searchform"; var formElements = document.getElementById(formName).elements; var checkBoxGroup = formElements['somefield']; var firstCheckbox = checkBoxGroup[0]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.