views:

397

answers:

1

Hi,

I have a form which is binded to a JQuery Form (AjaxForm) object.

In the form I have some radio buttons:

<input type="radio" id="dialog_stranka_dodajuredi_tip_fizicna" name="dialog_stranka_dodajuredi_tip" value="2" /> Selection 2
<input type="radio" id="dialog_stranka_dodajuredi_tip_pravna" name="dialog_stranka_dodajuredi_tip" value="1" /> Selection 1

Now, when the form gets posted via AJAX, the parameter "dialog_stranka_dodajuredi_tip" is empty. It doesn't have a value at all - regardless of which radio button is selected.

I also tried binding a change event like this:

 $('input[name=dialog_stranka_dodajuredi_tip]').bind('change', function(){ 

   switch (parseInt($('input[name=dialog_stranka_dodajuredi_tip]:checked').val())) {
     case 2: 
       alert('number 2 selected');
       break;
     case 1:
       alert('number 1 selected');
       break;
 } 
 });

But the val property has no value at all. The alert box doesn't pop up.

I've used firebug to debug and set watches at this point and this is the result (values):

$('input[name=dialog_stranka_dodajuredi_tip]').val()  -> value: ""
$('input[name=dialog_stranka_dodajuredi_tip]:checked').attr('id') --> value: "dialog_stranka_dodajuredi_tip_pravna"
$('input[name=dialog_stranka_dodajuredi_tip]:checked').attr('name') --> value: "dialog_stranka_dodajuredi_tip"
$('input[name=dialog_stranka_dodajuredi_tip]:checked').val() --> value: ""

As you can see, the val() simply doesn't return a value, although the value is set in the tag. I'm clueless, any ideas?

A: 

This works flawless for me.

copy/paste the following code

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">
      function a() {
        alert($('input[name=dialog_stranka_dodajuredi_tip]:checked').val());
        return false;
      }
    </script>
  </head>
  <body>
    <form action="">
      <input type="radio" id="dialog_stranka_dodajuredi_tip_fizicna" name="dialog_stranka_dodajuredi_tip" value="2"/> Selection 2
      <br>
      <input type="radio" id="dialog_stranka_dodajuredi_tip_pravna" name="dialog_stranka_dodajuredi_tip" value="1" /> Selection 1
    </form>
    <a href="#" onclick="javascript:a();">Check radio buttons</a>
</body>
</html>

to this page W3School Tryit and see for yourself

jitter
yes, it's working in this case.i don't know, it's strange - like i said, i'm clueless.in the case of my code the val() value is empty. i'm using jquery form and validate plugin. maybe there's a problem (some kind of incompatibility...)?
saso
I can't think of any. maybe post more code :)
jitter