hassank1 Posted January 1, 2009 Share Posted January 1, 2009 I want to create elements dynamically .. for example: when user select 3 in a list box I want 3 txtboxes (or other elements) to appear in the form .. if he press 2 (and 3 already selected then the 3 boxes disappear) and 2 textboxes shows.. etc.. and how should I name the dynamically created elements in a way that I know how to retreive them in the $_POST array and place them correctly in their place in the database. ? Link to comment https://forums.phpfreaks.com/topic/139085-create-elements-dynamically/ Share on other sites More sharing options...
Philip Posted January 1, 2009 Share Posted January 1, 2009 I typically do the input name + the number, for both the name/id So, you have a dropdown for X amount of "names" <input name='name1' id='name1'> <input name='name2' id='name2'> .... Then <?php if(isset($_POST['name1']) && !empty($_POST['name1'])) { // stuff } // OR // Change $i = to your max num of inputs you have. for($i=3; $i>0; $i--) { $name = 'name'.$i; // Set the name correctly, and then see if that variable is set. if(isset($_POST[$name]) && !empty($_POST[$name])) { // do stuff } } Just one way of many to do that. Link to comment https://forums.phpfreaks.com/topic/139085-create-elements-dynamically/#findComment-727499 Share on other sites More sharing options...
hassank1 Posted January 1, 2009 Author Share Posted January 1, 2009 ok thanks for the info u answered part of my question however I still need to know how to dynamically create elements in JS Link to comment https://forums.phpfreaks.com/topic/139085-create-elements-dynamically/#findComment-727658 Share on other sites More sharing options...
Philip Posted January 3, 2009 Share Posted January 3, 2009 This should be a good article to read up on: http://jennifermadden.com/javascript/dhtml/dynamicLayerContent.html Link to comment https://forums.phpfreaks.com/topic/139085-create-elements-dynamically/#findComment-728565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.