1
<option value="PRODUCT_TYPE">1.3</option>

I want to get 1.3 using below code but i m not getting it....

var OperatingSystem = document.getElementById("<%=ddlOS.ClientID %>"); 
var size = OperatingSystem.options.length; 

for (var i = 0; i < size; i++) { 
    if (OperatingSystem.options[i].text === obj.OperatingSystem) { 
        $("#ddlos").val(i); 
        $("#ddlOS").multiselect("refresh"); break;
    }
}

4 Answers 4

2

I solved this by using the following:

var OperatingSystem = document.getElementById("<%=ddlOS.ClientID %>"); 
var size = OperatingSystem.options.length; 
for (var i = 0; i < size; i++) 
{ 
   if (OperatingSystem.options[i].text === obj.OperatingSystem) 
 { 
   operatingsystem.selectedindex=i;
   $("#ddlOS option:selected).text();
   $("#ddlOS").multiselect("refresh"); 
   break;
 }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to look at the value returned from html() (or javascript innerHTML property) ion order to determine the visible selection content for the option. val() returns the tag's value property which in your example would be PRODUCT_TYPE.

Comments

0

As mike said, you can use innerHTML or Text.

You can get it with jquery like so:

http://jsfiddle.net/YNtxm/

function DoSomething()
{
var foo = $("select").find(":selected").text();
alert(foo);
}

1 Comment

it's not working because my dropdownlists is fill by database and i have more than 12 dropdownlists and when i enter a product_no in the textbox then all dropdownlists fill automaticallly but in my case its is not working before that is working when i doing simply operatingsystem.selectedindex=i but i want to do this like above code
0

You have several issues here. I would refactor to something like this:

var $ddl = $('<%=ddlOS.ClientID %>');
$ddl.val($ddl.find('option').filter(function () {
    return $(this).text() == obj.OperatingSystem;
}).val());

Here's a demo of the javascript: http://jsfiddle.net/uQfEA/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.