Skip to content

Instantly share code, notes, and snippets.

@nexocentric
Created March 19, 2014 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nexocentric/9636955 to your computer and use it in GitHub Desktop.
Save nexocentric/9636955 to your computer and use it in GitHub Desktop.
some javascripts for radio and select initalizations
//==========================================================
// [作成者]
// Dodzi Y. Dzakuma
// [概要]
// 選択されているグループステータスの初期値を設定する
// [引数]
// 1) 状況を表す整数
// [返り値]
// 無し
//==========================================================
function setDropdownBoxValue(dropdownId, value)
{
var selectBox = document.getElementById(dropdownId);
selectBox.value = value;
}
//==========================================================
// [作成者]
// Dodzi Y. Dzakuma
// [概要]
// 選択されているグループステータスの初期値を設定する
// [引数]
// 1) 状況を表す整数
// [返り値]
// 無し
//==========================================================
function setRadioGroupValue(radioGroupName, selectedRadio)
{
//------------------------------------
// 変数宣言
//------------------------------------
var radioGroup = document.getElementsByName(radioGroupName);
//------------------------------------
// 選択するラジオボタンを検索し、
// 発見時にそれを選択する
//------------------------------------
for (var button = 0; button < radioGroup.length; button++) {
//グループの一つのラジオボタン
var radioButton = radioGroup[button];
//見ているもののバリューと選択したいバリューが同じであれば選択する
if(radioButton.value == selectedRadio) {
radioButton.checked = true;
return;
}
}
//見つけられなかったので、最初のを選択する
radioGroup[0].checked = true;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment