Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My scenario:

I have dropdownlist with list of years,i need to check the value selected in the dropdownlist with the previous value selected in javascript code.

Dropdownmodelofthecar values are based on the year selected.

For example:
1)
Dropdownyear-2011
Dropdownmodelofthecar-listof cars.
submit button.

2)If i select
Dropdownyear-2011 again
Dropdownmodelofthecar - values should be retained..

i need the javascipt code :scenario
javascript function
{
if(previousyearvalueselected==presentyearvalue)
{
then retain the value,dont postback to get the carmodels
}
else
postback to get the carmodels
}

please do the needful
Posted
Comments
Sunasara Imdadhusen 7-Oct-10 2:43am    
Would you like to get only those records (car models) based on year selection?
chanti143143 7-Oct-10 3:16am    
s,postback should happen only when the currentvalueofyear selected is different from previousvalue selected.otherwise values must be retained and no postback should happen.
this i need to handle in javascript

var e = document.getElementById("<%=dropdown1.ClientID %>"); // select element
var strUser = e.options[e.selectedIndex].value;

var e2 = document.getElementById("<%=dropdown2.ClientID %>"); // select element
var strUser2 = e2.options[e2.selectedIndex].value;

if(strUser==strUser2)
{
then retain the value,dont postback to get the carmodels
}
else
postback to get the carmodels
 
Share this answer
 
Hi
Please use following:
XML
<select name="Dropdownyear" id="Dropdownyear" onchange="doPostbackEvent();">
       <option value="2006">2009</option>
       <option value="2007">2007</option>
       <option value="2008">2008</option>
       <option value="2009">2009</option>
       <option value="2010">2010</option>
   </select>

C#
function doPostbackEvent()
{
   //write your code here...
}


i have added onchange event to the dropdown and this event will call when you change any selected value else it do nothing.
in short the onchange event is call when you change selected item.
so you don't wont to write complex code for checking item changed :-\

Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 

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