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,211
  • 7
  • 28
  • 51
Haseeb Khan
  • 770
  • 2
  • 15
  • 37

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,211
  • 7
  • 28
  • 51
1

Try this:

    $selectedValue=$("#EditorFrame").contents().find("select#ModuleDropDown").val();
    alert($selectedValue);
Hearaman
  • 8,117
  • 13
  • 38
  • 56
0

You could try

$('#EditorFrame').contains().find("body").on("click", "#UploadButton", function(){
   alert($("#ModuleDropDown", window.parent.document).val());
});
Nicola Peluchetti
  • 74,514
  • 30
  • 136
  • 188