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. ? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 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.