Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my jquery code
i want to fetch the drop down list data
When I Have Click On Add Button IT Add "Undeffind" Value In table row
So what is the Solution for this

script type="text/javascript" src="http://code.jquery.com/jquery.min.js">

    $(document).ready(function(){
        $(".add-row").click(function()
		{
            var name = $("#name").val();
            var Relation = $("#Relation").val();
			var Date=$("#Date").val();
			
			var employed=$("#employed option:selected").val();
            var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + name + "</td><td>" + Relation + "</td><td>"+ Date +"</td><td>" + employed +"</td></tr>";
            $("table tbody").append(markup);
        });
        
        // Find and remove selected table rows
        $(".delete-row").click(function(){
            $("table tbody").find('input[name="record"]').each(function(){
            	if($(this).is(":checked")){
                    $(this).parents("tr").remove();
                }
            });
        });
    });

<pre><body>
    <form>
        <input type="text" id="name" placeholder="Family Member Name">
        <input type="text" id="Relation" placeholder="Relation">
		<input type="date" id="Date" placeholder="Date of Birth">
		<select name="Whether Employed" id="#employed" required> 
					<option value ="none">Select Here</option>
					<option value ="YES" text="Yes" Selected="selected">Yes</option>
					<option value ="No" text="No">No</option>
					</select>
    	<input type="button" class="add-row" value="Add Row">
    </form>
    <table>
        <thead>
            <tr>
                <th>Select</th>
                <th>Name</th>
                <th>Relation</th>
				<th>Date OF Birth</th>
				<th>Whether Employed(YES/NO)</th>
			</tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox" name="record"></td>
                <td>Peter Parker</td>
                <td>peterparker@mail.com</td>
				<td>					</td>
				<td>				</td>
            </tr>
        </tbody>
    </table>
    <button type="button" class="delete-row">Delete Row</button>
</body> 
</html>                                		


What I have tried:

When I Have Click On Add Button IT Add "Undeffind" Value In table row
So what is the Solution for this
Posted
Updated 30-Mar-17 21:45pm
v2

1 solution

remove the # from the id and try
id="#employed"

<select name="Whether Employed" id="employed" required>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900