Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're talking about the same general code you posted in <a href="https://stackoverflow.com/questions/638629/">your other question</a>, I believe you have to loop through the possible radiobuttons; there's no built-in whichRadioButtonIsSelected() function.</p> <p>You could do something like this:</p> <pre><code>function getRadioButtonValue(rbutton) { for (var i = 0; i &lt; rbutton.length; ++i) { if (rbutton[i].checked) return rbutton.value; } return null; } // then in your code, where "this" is the form object, and var rbvalue = getRadioButtonValue(this.radiobutton); // replace "radiobutton" with whatever the radiobutton group's name is </code></pre> <p><strong>edit:</strong> here's an example:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; body { background-color: black; color: white; } &lt;/style&gt; &lt;script type="text/javascript"&gt; function getRadioButtonValue(rbutton) { for (var i = 0; i &lt; rbutton.length; ++i) { if (rbutton[i].checked) return rbutton[i].value; } return null; } function handleClick(event) { if (console) console.info("handling click"); // for Firebug debugging, if you want it /* do something here */ alert(this.textBox1.value); alert("Favorite weird creature: "+getRadioButtonValue(this["whichThing"])); // I don't like alerts but it works everywhere if (console) console.info("handled click"); event.preventDefault(); // disable normal form submit behavior return false; // prevent further bubbling of event } function doit() { if (console) console.info("starting doit()"); document.forms.myform.addEventListener("submit", handleClick, true); return true; } &lt;/script&gt; &lt;/head&gt; &lt;body onload="doit()"&gt; &lt;form name="myform"&gt; &lt;div&gt; &lt;textarea name="textBox1" rows="10" cols="80"&gt; 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe; All mimsy were the borogoves, And the mome raths outgrabe. &lt;/textarea&gt; &lt;/div&gt; &lt;input type="submit" value="Update"/&gt; Which of the following do you like best? &lt;p&gt;&lt;input type="radio" name="whichThing" value="slithy toves" /&gt;Slithy toves&lt;/p&gt; &lt;p&gt;&lt;input type="radio" name="whichThing" value="borogoves" /&gt;Borogoves&lt;/p&gt; &lt;p&gt;&lt;input type="radio" name="whichThing" value="mome raths" /&gt;Mome raths&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload