0

this is my script

$.getJSON("Employee.js", function (data) { 
       var sample = data.one;alert(sample) });

and this is Employee.js file

var sample={ "one":"Manager","two":"Sr.Eng","three":"Eng" }

I am fine with this. i want to get the value from drop down list. i.e my drop down list will be like follow:

 <asp:DropDownList ID="ddlEmployee" runat="server">
                        <asp:ListItem>one</asp:ListItem>
                        <asp:ListItem>two</asp:ListItem>
                        <asp:ListItem>three</asp:ListItem>
                        <asp:ListItem>four</asp:ListItem>
                    </asp:DropDownList>

i an get the value of ddlEmployee in jscript as

var sel = document.getElementById("<%=ddlEmployee.ClientID%>");
        var opt = sel.options[sel.selectedIndex].text;

Bot how to use "opt" to get the value from Employee.js file?

2 Answers 2

1

You can use bracket notation:

var opt = 'one';

var sample = { "one":"Manager","two":"Sr.Eng","three":"Eng" };

var val = sample[opt]; // Manager
1
  • yes. this works fine $.getJSON("Employee.js", function (data) { var sample = data[opt]; alert(sample); })...
    – sms
    Oct 1, 2013 at 13:13
0

Try below code :

var data=$.("#ddlEmployee").val();

alert(data);
1
  • are you saying like this var sample = data.$("#ddlEmploee").value;alert(sample)... it will not work.
    – sms
    Oct 1, 2013 at 12:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.