PHP
PHP & jQuery checkbox 활용
HiroDaegu
2021. 12. 29. 22:12
728x90
SMALL


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TEST</title>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4544051457126963"
crossorigin="anonymous"></script>
<!-- jquery -->
<script type="text/javascript" src="/plugin/jquery/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
* {
text-align: center;
}
</style>
</head>
<body>
<?php
$name= "test";
$age = 100;
$numbers = 884440;
?>
<div class="cs_load">
<label for="cs_load">정보 불러오기</label> <input type="checkbox" id="cs_load" style="display: inline;">
</div>
<input type="text" class="txtBox" name="p_name">
<input type="text" class="txtBox" name="p_jumin">
<input type="text" class="txtBox" name="p_age" numonly>
<script>
$(function() {
$("input[type='checkbox']").on("click", function() {
var chk = $(this).is(":checked");
if(chk) {
$("input[name='p_name']").val("<?=$name?>");
$("input[name='p_age']").val("<?=$age?>");
$("input[name='p_jumin']").val("<?=$numbers?>");
} else {
$("input[name='p_name']").val("");
$("input[name='p_age']").val("");
$("input[name='p_jumin']").val("");
}
})
})
</script>
</body>
</html>
728x90
LIST