2014-11-23 112 views
-1

如何保存單選按鈕的值。一位朋友已經做到這一點,以獲得一個cookie。 現在我需要去下一步,但我不知道如何。如何保存單選按鈕值

功能saveForm(n表單){

var nFields = nForm.length; 
for (i=0; i<nFields; i++) 
    { 
    var isType = nForm[i].type; 
    alert(isType); 
    if (isType == 'radio'){alert('Field '+ i+ ' is a radio button')} 
    if (isType == 'select-one'){alert('Field '+i + ' is a select list')} 
    } 

}

<form onsubmit="return saveForm(this)"> 
     <input type = "radio" name = "staande_houding_globaal" value="0"> 
     0 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="1"> 
     1 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="2"> 
     2 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="3"> 
     3 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="4"> 
     4 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="5"> 
     5 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="6"> 
     6 </input> 
     <input type = "radio" name = "staande_houding_globaal" value="7"> 
     7 </input> 
     <input type="button" value="Volgende" onClick="history.forward()","saveState()" class = "volgende" /> 
    </form> 
+0

不是100%清楚什麼目標是 – charlietfl 2014-11-23 13:55:35

回答

0

得到單選按鈕的值嘗試

$("input:radio[name=staande_houding_globaal]").click(function() { 
alert($(this).val()); 
}); 

OR

var xyz = $("input[name=staande_houding_globaal]:checked").val(); 
console.log(xyz); 

使用此檢查的單選按鈕被選中或不

$('input[name=staande_houding_globaal]').is(":checked"); 

這將返回一個布爾值