Maybe not the best way, but this works for me:

<html>
  <head>
      <script type="text/javascript"
src="mochikit-svn/MochiKit/MochiKit.js"></script>
  </head>
  <body>
     <div id="radios">
        <input type="radio" name="test" value="1" />1<br />
        <input type="radio" name="test" value="2" />2<br />
        <input type="radio" name="test" value="3" />3<br />
     </div>
     <input type="button" value="check"
onclick="alert(filter(itemgetter('checked'), $$('#radios
input[name=test]'))[0].value);" />
  </body>
</html>

The code part with nicer formatting is:

var selectedvalue = filter(
  itemgetter('checked'),
  $$('#radios input[name=test])
)[0].value;

the "#radios" part is not strictly necessary, but it spares the
Selector module from traversing the whole document in searching for
the radiobuttons.

You end up with "undefined" if no radio is checked.

hth,
Arnar

On 12/13/06, Noufal <[EMAIL PROTECTED]> wrote:
>
> Hello everyone,
>   I've just been trying out Mochikit and I must say that it's really made life
> very easy.
>
>   I have a small question. It's probably because of my lack of experience with
> Javascript but here goes anyway. I have a small set of radiobuttons (sharing 
> the
> same name). I want to be able to send the value of the selected one to a cgi
> program using XMLHTTPRequest.
>
>   How do I get the state of the buttons so that I can send the actual value to
> the back end?
>
> Thanks much.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to