0

----EDIT----

I am making an jquery mobile application. Now I want to check which radiobutton is checked.

This is what I do in my javascript.

function filter(){
    if(document.getElementById('segment1').checked) {
         alert('Iedereen');
    }else if(document.getElementById('segment2').checked) {
         alert('team');
    }else{
        alert('favorieten');
    }
}

En this is my HTML

<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal" onchange=filter() > 
    <input type="radio" name="radio-view"  data-icon="segment-titlestyle-segonly"  id="segment1" value="choice1" checked="checked"/> 
    <label for="segment1"  id="controls">
    <span class="ui-btn-text-controls">Iedereen</span>
    </label> 
    <input type="radio" name="radio-view" data-icon="segment-titlestyle-segonly" id="segment2" value="choice2" /> 
    <label for="segment2" id="controls">
    <span class="ui-btn-text-controls">Team</span>
    </label> 
    <input type="radio" name="radio-view" data-icon="segment-titlestyle-segonly" id="segment3" value="choice3" /> 
    <label for="segment3" id="controls">
    <span class="ui-btn-text-controls">Favorieten</span>
    </label>  
</fieldset>

For some reason it doesn't work. Can anybody help?

kind regards.

Greg
  • 2,163
  • 1
  • 21
  • 23
Steaphann
  • 3,431
  • 3
  • 18
  • 15

2 Answers2

1

Your example working http://jsfiddle.net/Jgrgk/4/

kubedan
  • 616
  • 2
  • 7
  • 26
1
function AlertRadioId( groupName ) { //groupName is "radio-view"
    var radios = document.getElementsByName( groupName );
    for( i = 0; i < radios.length; i++ ) {
        if( radios[i].checked ) {
            alert(radios[i].value);
            return true;
        }
    }
}

need to call this function in a event of button / radio button onclick event

Dasarp
  • 194
  • 1
  • 5