DropDownList SelectedItem Javascript

A

Alper ÖZGÜR

Hi;
I can read the selectedvalue of dropdownlist by javascript using
this.value...
How can i get the selectedItem.text by javascript?
 
A

Alper ÖZGÜR

It returns the SelectedValue... Not SelectedText.....

haber said:
Alper,

this.options[this.selectedIndex].value

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Alper ÖZGÜR said:
Hi;
I can read the selectedvalue of dropdownlist by javascript using
this.value...
How can i get the selectedItem.text by javascript?
 
S

S. Justin Gengo [MCP]

Alper,

Sorry about that. I forgot to switch it from some of my code I copy and
pasted. It's pretty simple really. Just switch value to text.

this.options[this.selectedIndex].text

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Alper ÖZGÜR said:
It returns the SelectedValue... Not SelectedText.....

haber said:
Alper,

this.options[this.selectedIndex].value

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Alper ÖZGÜR said:
Hi;
I can read the selectedvalue of dropdownlist by javascript using
this.value...
How can i get the selectedItem.text by javascript?
 
Joined
Jul 3, 2008
Messages
1
Reaction score
0
Dropdownlist and javascript...

Hi.. I want to know a way to write a text in a textbox and find the item in a dropdownlist and put it in the top of the list? thanks...
 
Joined
Dec 18, 2008
Messages
1
Reaction score
0
Populate drop down as per the code written in text box

I have just used this method in one of my .net project. u just add this method in ur .js file and call this from ur aspx page.

function SearchItem(textbox, dropdown, chk)
{
if(chk)
{
for(var i=0; i<=dropdown.length; i++)
{
if(textbox.value == dropdown.value)
{
dropdown.selected = true;
break;
}
}
}
else
textbox.value = dropdown.value;
}

in controls page add this property in ur aspx page:
<asp:TextBox ID="txt" runat="server" MaxLength="20" OnBlur="javascript:SearchItem(<%=txt.ClientID %>,<%=ddl.ClientID %>,true);"></asp:TextBox>
<asp:DropDownList ID="ddl" runat="server" onchange="javascript:SearchItem(<%=txt.ClientID %>,<%=ddl.ClientID %>);" />
:flute:
 
Joined
Mar 26, 2011
Messages
1
Reaction score
0
Html.DropDownList("selItemsPerPage1", Model.Items, new
{
onchange = "alert($('#selItemsPerPage1 option:selected').val());"
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top