0

I have a dropdown outside the iframe

<select id="ModuleDropDown">
     <option>Hello world</option>
</select>

and I have an iframe like this

 <iframe id="EditorFrame" src="UploadTemplates.aspx" frameborder="0" style="height: 900px;
            width: 1000px" scrolling="auto"></iframe>

the code of UploadTemplate.aspx is:

<asp:Button ID="UploadButton" runat="server" Text="Upload"" />

so now my question is that how can I get the value of dropdown in iframe using jQuery I tried this but it doesn't help me

$("#UploadButton").click(function () {
    alert($("#ModuleDropDown").val());
});

but when I click the button I got undefined instead of value of dropdown please help me

Simon Edström
  • 6,461
  • 7
  • 32
  • 52
Haseeb Khan
  • 930
  • 3
  • 19
  • 41

3 Answers3

1

I think this one will to the trick for you:

$("#UploadButton").click(function () {
    alert($("#ModuleDropDown", window.parent.document).val())
})

The extra argument tells jQuery in which context that should be used.

Simon Edström
  • 6,461
  • 7
  • 32
  • 52
1

Try this:

    $selectedValue=$("#EditorFrame").contents().find("select#ModuleDropDown").val();
    alert($selectedValue);
Hearaman
  • 8,466
  • 13
  • 41
  • 58
0

You could try

$('#EditorFrame').contains().find("body").on("click", "#UploadButton", function(){
   alert($("#ModuleDropDown", window.parent.document).val());
});
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192