0

what i'm trying to do is whenever the user click add more button a new select tag will be created i manage to create the select tag but whenever i'm trying to add the options for my select tag it didn't show up here's my code

jQuery :

 $(".addjob").click(function(){

     $("<tr><td>Choose Job Title</td><td><select name='jobtitles_id' class='jobtest' ></select></td></tr>").insertAfter($(this).parents("tr:last"));
     addjobtitle();
 });

Here is my html/php code

<tr classs="afterthis">
<td>Choose Job Title</td><td><select name="jobtitles_id" style="min-width:145Px"><?php
    $rows1 = array();
    $result1 = $db->query("job_titles", " WHERE id NOT IN (SELECT jobtitles_id FROM categorybridge) ORDER BY name ASC ");
                $selected1 = '';
        while($rows1 = mysql_fetch_array($result1)) {
                    if($rows1['name'] == 'none'){
                    $selected1 = "selected";        
                    }
             ?> 
            <option value="<?php echo $rows1['id']; ?>" <?php echo $selected1; ?>><?php echo ucwords($rows1['name']); ?></option>       
    <?php $selected1 = ''; } ?>
    <option value="26" >None</option>   
    </select></td><td><div class="addjob" >Add another Job Title</div></td>
</tr>

BTW the value from my select tag comes from mySql and i dont know what to do :(

please kindly help me.. thanks in advance!

user2016791
  • 11
  • 1
  • 4
  • 3
    Where is your code to insert `option` elements? – mrtsherman Jan 28 '13 at 02:54
  • Are there going to be multiple select tags in the dom simultaneously, or will they go away once a selection is made? If they're supposed to be persistent, it would be a good idea to give each one a unique name. [Not required](http://stackoverflow.com/questions/452066/html-form-with-multiple-hidden-control-elements-of-the-same-name), just a good idea. – Austin Mullins Jan 28 '13 at 03:02
  • You should post your html. Based on the jQuery you posted, I think you are doing something wrong. `$(this).parents("tr:last")` doesn't make much sense, as I would expect there to be only one table. Why is `last` in there? – mrtsherman Jan 28 '13 at 03:06
  • Sorry guys i already edit it you can see it now – user2016791 Jan 28 '13 at 03:10
  • Can you post your rendered html? Server-side code is not generally useful for answering client-side questions. You still didn't post your javascript that inserts the options. This makes me think that perhaps you want to be cloning an existing select list instead of creating a completely new one? – mrtsherman Jan 28 '13 at 03:17
  • Try posting a fiddle. (edit the code, click the save, then cut and the paste the url into your question). http://jsfiddle.net/NUET3/ – mrtsherman Jan 28 '13 at 03:20
  • @mrtsherman That's my guess, too. It seems like there should just be an ajax call to a page that just delivers the ` – Austin Mullins Jan 28 '13 at 03:22

1 Answers1

0

Shot in the dark here, but I think this is what you are trying to do based on code posted.

http://jsfiddle.net/NUET3/1/

Monitor the table for when addjob is clicked. When clicked, clone its table row and append it to the table.

$('table').on('click', '.addjob', function() {
    var $clone = $(this).parents('tr').clone();
    $('table').append($clone);
});
mrtsherman
  • 39,342
  • 23
  • 87
  • 111