Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Razor Dropdownlist as:
@Html.DropDownList("TnDscode",null,new{@id="cmbTnDscode" ,@size="1.2"})


In controller code for Dropdownlist:
ViewBag.TnDscode = new SelectList(db.Districts, "DsCode", "DsName");


In JavaScript:
document.getElementById("cmbTnDscode").value="Mumbai"; 


But It is not working...
to set selected value of Dropdownlist to "Mumbai" can anyone help??
Posted

1 solution

Hi Priyanka,

Please try this code

JavaScript
document.getElementById('cmbTnDscode').value = 'DsCode value'


you have to write value equals "DsCode" which you have use in controller.
 
Share this answer
 
Comments
priyankavm 29-Aug-13 7:56am    
Hi Hitesh..

I have tried this but still its not working...
Hitesh Gohel 30-Aug-13 2:01am    
Hi Priyanka,

Pls tell me what you get from this code document.getElementById("cmbTnDscode").value
if you get DsCode then this works else you get DsName then it not works..
Hitesh Gohel 30-Aug-13 2:03am    
Hi Priyanka,
you are using Jquery then write this code in document.ready other wise in window.onload event.
priyankavm 30-Aug-13 6:15am    
thankss
Hitesh Gohel 30-Aug-13 7:24am    
you'r welcome..

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