how to change ids for dynamic rows when user select drop down

how to change id's of the  text boxes when use select drop down value to 'Country';

when user select 'Country' then 3 dynamic rows will be displayed.

how to. change the id's of the  text boxes[Employee Value].first text box  id should change to 'country,2nd text box id be 'state' and 3rd textbox city.

if user select other option then text box id should be as it is..

<script src=""></script>
<script src=""></script>

var sample=
        "company": 123,
        "organizationMap": {
            "Country": [


                        var $tr = $(this).closest('tr');
                        var allTrs = $tr.closest('table').find('tr');

                        var lastTr = allTrs[allTrs.length-1];
                        var $clone = $(lastTr).clone();


                            var el = $(this).find(':first-child');
                            var name = el.attr('name') || null;
							  var id = el.attr('id') || null;
                          if(name !=null && name.indexOf("[") > -1)
										var number= parseInt(name.substring(name.indexOf("[")+1, name.indexOf("]")));
										var tillfirstsquare= name.substring(0,name.indexOf("[")+1);
										var tillfirsttolastsquare =name.substring(name.indexOf("]"),name.length);
										var result=tillfirstsquare+number+tillfirsttolastsquare;
										el.attr('name', result);
										 el.attr('id', id+parseInt(number));





				$('#addattributedivtable > tbody  > tr:gt(1)').remove();
				if( $('#addattributedivtable > tbody  > tr:last').find('td:last-child').find("#addrow").length ==0)
				   $('#addattributedivtable > tbody  > tr:last').find('td:last-child').append("<input type='button' id='addrow' name='addrow' value='addrow' />");
									for(var i=0;i<sample[0].organizationMap[$(this).find('option:selected').text()].length;i++)
									   $( "#addrow" ).trigger( "click" );
											$( ".datepick" ).datepicker();	 



<table border="1" class="table table-striped table-hover  table-bordered" id="addattributedivtable">

<td name="deleterow" id="deleterow" class="deleterow"></td>

<td><label class="col-md-3 control-label" >Employee Names</label>

<label class="col-md-3 control-label" >Employee Value</label>

<td class="addrow">&nbsp;</td>


<td name="deleterow" class="deleterow"></td>

<select id="allemployees" name="employeeChange[0].name" class="form-control">
<option value="0" selected="">Please Select Employee</option>
<option value="6">Country</option>
<option value="6">company</option>

<td><input id="employeeValue" name="employeeChange[0].employeeValue" size="45" type="text" >

<input type="button" id="addrow" name="addrow" value="addrow">


Open in new window

LVL 20
chaitu chaituAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$(document).on("change", "select[id=allemployees]", function() {
     if($(this).attr("selectedIndex") == 1) { // if second item (Country) in the dropdown in selected
          var theRow = $(this).closest("tr"); // get row of the dropdown
          var employeeValue = theRow.find("[id=employeeValue]");
          var secondTextbox = theRow.find(":text:eq(1)");
          var thirdTextbox = theRow.find(":text:eq(2)");

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chaitu chaituAuthor Commented:
its not working.all text boxes  are not in the same text in first row,2nd text box in 2nd row and so on..
So post a complete table to see what you really have
chaitu chaituAuthor Commented:
please see my original post .when select drop down value it will display dynamic rows.
I see a table and two rows, I can't imagine your dynamic row, post them
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.