html - Problem with dynamic checkbox to relate with corresponding textbox -
i have 1 form user can dynamically add new text box. each textbox, have 1 checkbox (for option show or hide in frontend). it's below.
<ul> <li><input type="text" name="field_name[]" /></li> <li><input type="checkbox" name="show_hide[]" /></li> </ul>
<input type="button" value="add more field">
when post value php, confused how can related checkbox corresponding textbox since array of checkbox 'show_hide[]' may depends upon user input.
you use index:
<ul> <li><input type="text" name="field_name[0]" /></li> <li><input type="checkbox" name="field_name[0]" /></li> </ul>
and jquery, every time add new text box , checkbox set name show_hide[index] etc. store index globally , update when new text box added, or use regex parse previous input last index , increment way. on server you'll array can check. other way like:
<ul> <li><input type="text" name="field_name[0][text]" /></li> <li><input type="checkbox" name="field_name[0][checked]" /></li> </ul>
which give bit of nicer array work :-)
Comments
Post a Comment