views:

1687

answers:

2

How do I go about doing this with jQuery?

Basically the structure:

<form id="myForm">
  <iframe>
    <!-- Normal HTML headers omitted -->
    <input type=radio name="myRadio" value=1>First
    <input type=radio name="myRadio" value=2>Second
    <input type=radio name="myRadio" value=3>Third
  </iframe>
  <input type=button value="Submit" />
</form>

I tried various examples from the net such as

$("input[@type=radio][@checked]");

But failed. Even with jQuery form plugin's .fieldValue() failed.

+5  A: 

try $('#myForm iframe').contents().find('input[name=myradio]').val() I'll assume that the iframe contents have already been loaded and are accessable e.g same domain

redsquare
Nice, but I get "on" eventhough nothing is being selected...
SyaZ
Actually, this worked. I used <input ... val=1> instead of value=1. My fault, typo.
SyaZ
A: 

Unless jQuery does some magic I'm not aware of, accessing another frame's DOM requires a little trickery. This may work:

var frameDocument = $('#myForm iframe').contentDocument || $('#myForm iframe').contentWindow.document;
$(frameDocument).find('input[type=radio][checked]');

And, note this from the jQuery documentation:

Note the "@" before the attribute name was deprecated as of version 1.2.

eyelidlessness