-2

I have a table and i am adding new rows dynamically. Everything is working fine except my select. I am able to hold all the values of my field except the select field.

So it is something like this When the user fills the form and click on initiate button, he is directed to second screen which is verification screen where he can verify the details and if wants to modify anything he can click on modify button and he will be redirected to first screen. So the problem is the values filled by the user is retained in all the field but the value of the drop-down is not retained and is showing default value 'Select'.

Also i am able to get the selected value in array from 2nd to 1st screen and also i am able to assign the value to it but still its not displaying on the screen .Here's how.

Code

document.getElementById('fldsearch'+temp).options[document.getElementById('fldsearch'+temp).selectedIndex].value  = arrsearch[temp];

arrsearch[temp] is an array where the selected value is stored.

fldsearch is the <td id> of select field.

temp is the increasing number of <td id> since i am adding rows dynamically.

Please do let me know if you need anything else.Thanks

Saurav
  • 17
  • 7

1 Answers1

0

First you have to set all values to drop-down. If all values are bind to select then one of them can be set to default value. Take a look at below example. Also please find fiddle link in comments.

<select name="ddlTitles" id="ddlTitles">
    <option value="">Select</option>

</select>

$(function() {
    var titles = ["Mr.","Ms.","Mrs.","Miss."]; 
   for(var i=0;i<titles.length;i++){           
             var titleElement = document.getElementById("ddlTitles");
             var option = document.createElement("option");
             option.text = titles[i]
             option.value = titles[i]
             titleElement.add(option);          
   }
   //Set default value to Ms.
   $("#ddlTitles").val("Ms.");
});
Shiv Patne
  • 543
  • 3
  • 10