0
0

チェックボックスの状態を取得し、apiで表示を変更するサンプル

async function entertainer_api() {
	api_val = getValue("api_val");
	let form = new FormData();
	form.append("api_val", api_val);
	const url = "/api.php";
	await fetch(url, {
		method: 'POST',
		body: form,
	})
	.then(response => response.json())
	.then(data => {
		var update_ul = document.getElementById("re_ul");
		update_ul.innerHTML = "";
		if(data.retuen_list) {
		  re_ul.innerHTML = data.retuen_list;
		}
	})
	.catch(error => {
		console.error('通信に失敗しました', error);
	});
}

function getValue(classname) {
	var checks = document.getElementsByClassName(classname);
	var str = '';
	for ( i = 0; i < checks.length; i++) {
		if ( checks[i].checked === true ) {
			if(i > 0) {
				str += ",";
			}
			str += checks[i].value;
		}
	}
	return str;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0