Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  34] [ 4]  / answers: 1 / hits: 16373  / 11 Years ago, fri, june 7, 2013, 12:00:00

I have drop down list declared like :



    <asp:DropDownList ID=myDropDown width=300 CssClass=textboxda 
AutoPostBack=True runat=server onmousewheel=return false; />


Drop down list change method



myDropDown.Attributes.Add(OnChange, return OnChange(););


function OnChange()
{
var $j = jQuery.noConflict();

var sel = $j(this).prevAll(#myDropDown:first),
val = sel.val(),
text = sel.find(':selected').text();

alert(text);
}


I am populating this drop down dynamically.



I am fetching the last/previously selected text of the drop down, but this is not working.



Please suggest.


More From » jquery

 Answers
11
myDropDown.Attributes.Add(OnChange, return OnChange(this););


after that you can put another attribute for current selected item



myDropDown.Attributes.Add(previous, your default selected value);


after that your function like this



function OnChange(args)
{

var previousVal=$(args).attr('previous');
var newVal=$(args).find(':selected');
alert(previousVal);
alert(newVal);
$(args).attr('previous',newVal);
}

[#77762] Wednesday, June 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarettajb

Total Points: 678
Total Questions: 94
Total Answers: 90

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;