2009-11-17 2 views
0

두 개의 테이블을 만들었습니다. 첫번째는 우편물 주소 (우편물 거리, 도시 등)입니다. 두 번째 표는 배송 주소입니다. 필드는 우편 주소와 거의 같습니다. 배송 주소가 우편 주소와 같다고 가정합니다. 어떻게 첫 번째 테이블의 데이터를 두 번째 테이블로 복사 할 라디오 버튼을 만들 수 있습니까?사용자 입력 데이터 세트를 양식의 다른 영역으로 전달

사용자가 입력 한 데이터는 MySQL 데이터베이스에 저장됩니다.

어떻게 이런 일을 할 수 있습니까?

<script type="text/javascript"> 
function data_copy(){ 
    if(document.form1.copy[0].checked){ 
     document.form1.txtmailing_add2.value=document.form1.txtmailing_add1.value;   document.form1.Address.txtother_street.value=document.form1.Address.txtmailing_street.value; 
     document.form1.Address.txtother_city.value=document.form1.Address.txtmailing_city.value;  document.form1.Address.txtother_state.value=document.form1.Address.txtmailing_state.value; 
     document.form1.Address.txtother_postcode.value=document.form1.Address.txtmailing_postcode.value;   document.form1.Address.txtother_country.value=document.form1.Address.txtmailing_country.value; 
    } 
    else{ 
     document.form1.Address.txtmailing_add2.value=""; 
     document.form1.Address.txtother_street.value=""; 
     document.form1.Address.txtother_city.value=""; 
     document.form1.Address.txtother_state.value=""; 
     document.form1.Address.txtother_postcode.value=""; 
     document.form1.Address.txtother_country.value=""; 
    } 
} 

</script> 

<form name=form1 method=post action=""> 
</form> 
내가 생각
+0

, 당신이 내가 시도 – sathish

+0

표에 값을 라디오 버튼을 클릭하면, 자바 스크립트를 사용하여 배송 주소로 우편 주소의 값을 전달하고 저장할 수 있습니다 : 여기에 지금까지 시도 무엇 그것을 해결하기 위해 자바 스크립트를 사용하십시오. 그러나 일은 없다. –

+0

그런 다음 onSubmit에서 조건을 확인하십시오. 확인란 또는 옵션 상자가 선택된 경우 우편 주소의 값을 두 테이블에 모두 추가하십시오. – sathish

답변

0
<script type="text/javascript"> 

function data_copy() { 

    // assuming naming conventions are consistent. 
    var fieldIDs = ['street', 'city', 'state', 'postcode', 'country']; 

    var copy = document.getElementsByName('copy'); //using name attribute for reference 

    if (copy[0].checked) { 

     // note we are expecting the 'id' attribute to be set for the elements. 
     var txtmailing_add1 = document.getElementById('txtmailing_add1'); 
     var txtmailing_add2 = document.getElementById('txtmailing_add2'); 

     // make sure we have valid objects before accessing their properties 
     if (txtmailing_add1 && txtmailing_add2) { 
      txtmailing_add2.value = txtmailing_add1.value; 
     } 

     // for the remaining fields we can look our field id list and generate an id 
     // by combining the expected convention with the given unique string 
     for (var j = 0; j < fieldIDs.length; j++) {     
      var mailingField = document.getElementById('txtmailing_' + fieldIDs[j]); 
      var otherField = document.getElementById('txtother_' + fieldIDs[j]); 
      if (mailingField && otherField) { 
       otherField.value = mailingField.value; 
      } 
     } 

    } 
    else { 
     // same process, just skipping the 'mailing' fields 
     var txtmailing_add2 = document.getElementById('txtmailing_add2'); 

     if (txtmailing_add2) { 
      txtmailing_add2.value = ''; 
     } 

     for (var j = 0; j < fieldIDs.length; j++) { 
      var otherField = document.getElementById('txtother_' + fieldIDs[j]); 
      if (otherField) { 
       otherField.value = ''; 
      } 
     } 
    } 
} 

</script> 
<form name="form1" method="post" action="" onsubmit="data_copy();"> 
copy: <br /> 
<input type="radio" name="copy" value="1" /> yes<br /> 
<input type="radio" name="copy" value="0" /> no<br /> 
<!-- form fields --> 
</form> 
관련 문제