두 개의 라디오 버튼 - '이탈리아어'& '스페인어'가 있습니다. 하나를 선택하면 '기본'입력과 '시작'입력이 다른 파일에서 채워지도록 자동 완성되지 않습니다. 따라서 '스페인어'를 선택하면 http://xxx/spanish.php에서 자동 완성되며 '이탈리아어'를 확인하면 http://xxx/italian.php에서 자동 완성됩니다.자바 스크립트 라디오 버튼 문제
var radio1 = document.getElementById("radio1");
var radio3 = document.getElementById("radio3");
if (radio1.checked){
alert("radio1 selected");
//Starter Autocomplete (Spanish)
var starterSearchData;
$(function() {
$.ajax({
url: "http://learn.cf.ac.uk/webstudent/sem5tl/javascript/assignments/spanish.php",
dataType: "jsonp",
async: false,
success: function(data) {
starterSearchData = $.map(data, function(item) {
if (item.course == "starter")
return item.name;
});
EnableAutoComplete();
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function EnableAutoComplete() {
$("#starter").autocomplete({
source: starterSearchData,
minLength: 2,
delay: 010
});
}
});
//Main Autocomplete (Spanish)
var mainSearchData;
$(function() {
$.ajax({
url: "http://learn.cf.ac.uk/webstudent/sem5tl/javascript/assignments/spanish.php",
dataType: "jsonp",
async: false,
success: function(data) {
mainSearchData = $.map(data, function(item) {
if (item.course == "main")
return item.name;
});
EnableAutoComplete();
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function EnableAutoComplete() {
$("#main").autocomplete({
source: mainSearchData,
minLength: 2,
delay: 010
});
}
});
}else if (radio3.checked) { .... same code, except url changed to http://xxx/italian.php... }
HTML :
<div id="radio">
<input type="radio" id="radio1" name="radio"><label for="radio1">Spanish</label>
<input type="radio" id="radio3" name="radio"><label for="radio3">Italian</label>
</div>
<label for="starter">Choose starter</label>
<input type="text" name="starter" id="starter"><br>
<label for="main">Choose main</label>
<input type="text" name="main" id="main"><br>
AJAX 호출, 내가 if 문을하려고 할 때 등, 작동하지만, 필드가 채워지지 않는다/자동 완성.
감사합니다.
당신이 콘솔에서 점점 어떤 오류? – Curiousdev
하나의 아약스 호출이 있고 단순한 조건에서 라디오 버튼을 사용하여 올바른 값을 설정하거나 URL 매개 변수를 보내 쿼리/결과를 필터링하도록합니다. 예'assignments /? Lang = ****** & Course = ******'이 방법을 사용하면 하나의 PHP 파일을 처리하여 올바른 쿼리를 반환 할 수 있습니다. – NewToJS
Curiousdev - 메시지를받는 중 .. "Uncaught TypeError :"if (radio1.checked) { "행에 대해 'checked of'null '속성을 읽을 수 없습니다. – Tatws24