2012-11-06 2 views
-1

두 개의 다른 선택기를 변경하면 두 개의 다른 테이블을 채울 필요가 있습니다. 각 테이블은 각각 ​​해당 테이블을 가리켜 야합니다. 나는 다른 것을 시도했지만 잘못된 길을 찾고 있다고 생각합니다. 어떤 생각? 어떤 힌트?두 개의 다른 테이블 채우기

<html> 
<head> 
<script> 

function showUser(str) 
{ 
if (str=="") 
    { 
    document.getElementById("txtHint").innerHTML=""; 
    return; 
    } 
if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
    {// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText; 
    } 
    } 
xmlhttp.open("GET","getuser.php?q="+str,true); 
xmlhttp.send(); 
} 
</script> 

</head> 

<body> 

<form> 
<select name="users" onchange="showUser(this.value)"> 
<option value="">Select a person:</option> 
<option value="1">Peter Griffin</option> 
<option value="2">Lois Griffin</option> 
<option value="3">Glenn Quagmire</option> 
<option value="4">Joseph Swanson</option> 
</select> 
</form> 
<br /> 
<div id="txtHint"><b>Person info will be listed here.</b></div> 

<form> 
<select name="users" onchange="showUser(this.value)"> 
<option value="">Select a person:</option> 
<option value="1">Peter Griffin</option> 
<option value="2">Lois Griffin</option> 
<option value="3">Glenn Quagmire</option> 
<option value="4">Joseph Swanson</option> 
</select> 
</form> 
<br /> 
<div id="txtHint2"><b>Person info will be listed here.</b></div> 

</body> 
</html> 
+0

무엇이 질문입니까? 작동하지 않는 것은 무엇입니까? – bidifx

+0

네 말이 맞아, 나는 그 질문에 대해 더 구체적이어야한다. 그것은 될 것입니다 : 어떻게 내가 선택기의 변화에 ​​해당 테이블을 가리 키도록 내 스크립트를 만들 수 있습니까? –

답변

0

당신은 같은 함수에 두 번째 매개 변수를 추가 할 수 있습니다

function showUser(str, hintId) { /* ... */} 

추가, 그래서 같이 현재의 힌트 DIV의 요소 ID를 전달합니다

다음
<select name="users" onchange="showUser(this.value, 'txtHint')"> 
... 
<select name="users" onchange="showUser(this.value, 'txtHint2')"> 

, getElementById을 사용할 때 코드의 아무 곳이나 hintId 매개 변수를 사용하십시오.

document.getElementById(hintId).innerHTML=""; 
+0

고마워요, 한번 시도해 볼게요. 좋아 보인다. –

+0

트릭을해야 할 것입니다. 어떤 문제라도 발견하면 멀리 물어보십시오. 그렇지 않으면 답을 랭크하는 것이 좋습니다. – iMoses

+0

WOW WOW WOW, 매력처럼 작동합니다! :) 나는 일종의 새로운 그래서 나는 주위에 역동적 인 답변을 순위 및 그 물건을 알고 있어요. 고마워. @ 모세. –

관련 문제