체크박스 클릭하면 텍스트 입력 필드 복사하기 예제

2018. 3. 5. 15:08Javascript/Javascript+jQuery

반응형

<script>

function FillBilling(f) {
if(f.billingtoo.checked == true) {
f.billingname.value = f.shippingname.value;
f.billingcity.value = f.shippingcity.value;
}
}

</script>


To add more fields, just add to the parameters shown above...like this:
f.billingstate.value = f.shippingstate.value;
f.billingzip.value = f.shippingzip.value;
The HTML for the form you will use looks like this:

<b>Mailing Address</b>
<br><br>
<form>
Name: <input type="text" name="shippingname">
<br>
City: <input type="text" name="shippingcity">
<br>
<input type="checkbox" name="billingtoo" onclick="FillBilling(this.form)">
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<P>
<b>Billing Address</b>
<br><br>
Name: <input type="text" name="billingname">
<br>
City: <input type="text" name="billingcity">
</form>



<script type="text/javascript">

function allCheck() {

var checkboxes = document.getElementsByName('approve[]');
var button = document.getElementById('toggle');

if (button.value == 'select') {
for (var i in checkboxes) {
checkboxes[i].checked = 'FALSE';
}
button.value = 'deselect'
} else {
for (var i in checkboxes) {
checkboxes[i].checked = '';
}
button.value = 'select';
}
}
</script>


반응형