비전공자 개발일기

PHP & jQuery checkbox 활용 본문

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>&nbsp;&nbsp;&nbsp;<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

'PHP' 카테고리의 다른 글

PHP with if condition  (0) 2021.12.31
PHP with Select Option  (0) 2021.12.30
PHP 5일차  (0) 2021.12.25
PHP 4일차 (배열 출력)  (0) 2021.12.23
PHP 3일차  (0) 2021.12.22