Tom_S Posted October 29, 2009 Share Posted October 29, 2009 Sorry for the lack of detailed subject - I'm not quite sure how to describe it in a short space; I have a form: <select id="1[]" name="1[]"><option value="1">1</option><option value="2">2</option> (and so on - lots of options)</select> <input type="text" id="2[]" name="2[]" /> And a button below which adds another set of those fields, which has no limit. The value of the input is specific to the selection made before. What I would like to do is, for each pair of input and select values, write something to a file.. for example: "You chose an $select1 with the name $input2" I have looked into writing a file and that shouldn't be too hard for me, but im not sure how to pair each selection to the text input, could someone suggest how to do this? Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 29, 2009 Share Posted October 29, 2009 Well, first of all, I would highly discourage using "1" and "2" as field names (assuming that wasn't just for illustrative purposes). Use a meaningful name. Anyway, you are creating the field names in a way that they will be processed by PHP as unindexed arrays. Therefore, PHP will give them numeric indexes starting at zero. Assuming you have exactlythe same number of field 1's and field 2's and they are in the same order as they are to be paired, you should be able to make the association that $field1[0] is paired with $field2[0], and $field1[1] is paired with $field2[1], and so on. However, I would prefer to be more explicit and to give my fields explicit indexes to ensure they are paired correctly <select name="field1[0]"> <option>1</option> <option value="2">2</option> </select> <input type="text" name="field2[0]" /> <select name="field1[1]"> <option>1</option> <option value="2">2</option> </select> <input type="text" name="field2[1]" /> ...etc. Quote Link to comment Share on other sites More sharing options...
Tom_S Posted October 29, 2009 Author Share Posted October 29, 2009 Ok, so im using the following names: <select> : aircrafttype <input> : aircraftreg And I've changed it so each set have their own id, like so: <select name="aircrafttype[0]"> <option>1</option> <option value="2">2</option> </select> <input type="text" name="aircraftreg[0]" /> <select name="aircrafttype[1]"> <option>1</option> <option value="2">2</option> </select> <input type="text" name="aircraftreg[1]" /> I also forgot to mention: I have a button next to each set which removes that particular set of inputs, so the order will not always be set 1, then set 2 and so on. Quote Link to comment Share on other sites More sharing options...
Tom_S Posted October 29, 2009 Author Share Posted October 29, 2009 Nevermind.. I've figured out what I want to do. 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.