Mi Lugarcito
Javascript - input 숫자필드 자동계산하기 본문
<div class="floor">
<div class="panel">
<div class="panel-heading" id="label">
<h4> <i class="ion-ios-information"></i> {{xe_trans($config->get('label'))}} 정보 입력</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<label>현재 층 입력</label>
<div class="input-group">
<input type="text" class="mmoa_currentFloor form-control filter-input" name="{{$config->get('id')}}_currentFloor" id="currentFloor" onkeyup="percentCal()" placeholder="현재층을 입력하세요" />
<div class="input-group-append d-none">
<span class="input-group-text" id="basic-addon2">층</span>
</div>
</div>
</div>
<div class="col-md-6">
<label>전체 층 입력</label>
<div class="input-group">
<input type="text" class="mmoa_totalFloor form-control filter-input" name="{{$config->get('id')}}_totalFloor" id="totalFloor" onkeyup="percentCal()" placeholder="전체층을 입력하세요." />
<div class="input-group-append d-none">
<span class="input-group-text" id="basic-addon2">층</span>
</div>
</div>
</div>
<div class="col-md-12">
<label>고층/중층/저층</label>
<div class="input-group">
<input type="text" class="mmoa_percentFloor form-control filter-input" name="{{$config->get('id')}}_percent" id="percent" readonly/>
</div>
</div>
</div>
</div>
</div>
</div>
//현재층 , 전체층 알고리즘
function percentCal()
{
var currentFloor = document.getElementById("currentFloor").value;
var totalFloor = document.getElementById("totalFloor").value;
document.getElementById('percent').value = (parseInt(currentFloor) / parseInt(totalFloor)).toFixed(2);
var percent = document.getElementById('percent').value;
console.log(percent);
}
'JavaScript' 카테고리의 다른 글
Axios 통신 - Object with array key and array value 공부 (0) | 2021.12.06 |
---|---|
JavaScript - push / pop 등 배열 공부하기 (0) | 2021.09.06 |
Button - 숨겨져있는 hidden div 버튼 클릭시 show div 나타나게 하기 (0) | 2021.09.05 |
CheckBox - 체크박스 선택시 div 나타나게 하기 (0) | 2021.09.05 |
Radio & Input - 라디오버튼 선택시 텍스트박스 활성화/비활성화 (0) | 2021.09.05 |