sub_title
 웹개발 질문과답변
제   목 비만도 계산 스크립트 질문드립니다 ㅠㅠ
작성자 샤샤 등록일 2017-04-05 08:42:32 조회수 10,598

<html>
<head>
    <title>해피CGI</title>

<style type="text/css">
#dhtmlgoodies_bmi_calculator{
    margin-left:10px;
    width:380px;    /* Width of entire calculator */
    height:400px;    /* Height of entire calculator */
    font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;    /* Fonts to use */
}
#dhtmlgoodies_bmi_calculator .calculator_form{    /* Form */
    width:170px;    /* Width of form div */
    float:left;    /* Position the form at the left of the graph */
    padding-left:5px;
    padding-right:5px;
}
#dhtmlgoodies_bmi_calculator input{
    width:130px;
}
#dhtmlgoodies_bmi_calculator .calculator_form .textInput{
    width:40px;    /* Width of small text inputs */
    text-align:right;    /* Right align input text */
}
#dhtmlgoodies_bmi_calculator .calculator_graph{
    width:198px;    /* Width of graph div */
    float:left;    /* Position bar graph at the left */        
    background-color:#DDD;    /* Light gray background color */
    border:1px solid #555;    /* Gray border around graph */
    
    height:100%;
    position:relative;
}

.calculator_graph .graphLabels{    /* Help labels at the top of the graph */
    background-color:#FFF;    /* White bg */
    padding:3px;    /* Some air */
    margin:2px;    /* Around around help div */
    border:1px solid #555;    /* Gray border */

}
.graphLabels .square{    /* Small square showing BMI, e.g.: Below 18.5: Underweight */
    height:12px;    /* Width of square */
    width:12px;    /* Height of square */
    border:1px solid #000;    /* Black border */
    margin:1px;     /* "Air" */
    float:left;        
}
.graphLabels .label{    /* Help text, , e.g.: Below 18.5: Underweight */        
    width:130px;    /* Width */
    height:14px;    /* Height */
    font-size:11px;    /* Font size */
    padding-left:2px;    /* Space at the left of label */
    float:left;
}

.barContainer{    /* DIV for both the multicolor bar and users weight bar */
    position:absolute;
    bottom:0px;
    border:1px solid #000;
    border-bottom:0px;
    text-align:center;
    vertical-align:middle;
}
.barContainer div{    /* colored div inside "barContainer */
    border-bottom:1px solid #000;
}
.barContainer .labelSpan{    /* Label indicating users BMI */
    background-color:#FFF;    /* White BG */
    border:1px solid #000;    /* Black border */
    padding:1px;    /* "Air" inside the box */
    font-size:11px;    /* Font size */
}

.clear{    /* Clearing div - you shouldn't do anything with this one */
    clear:both;
}
    
</style>
<script type="text/javascript">
/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.   

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/
    
var useCm = true;     // Using centimetre for height, false = inch
var useKg = true    // Using kilos for weight, false = pounds
var graphColors = ['#6600CC','#66CC00','#00CCCC','#CC0000'];
var graphLabels = ['18.5 이하: 살좀더찌삼','18.5~24.9: 정상','25.0~29.9: 비만위험','30이상: 비만'];
var labelsPerRow = 1;    /* Help labels above graph */
var barHeight = 300;     // Total height of bar
var barWidth = 50;        // Width of bars */

// Don't change anything below this point */

var calculatorObj;
var calculatorGraphObj;
var bmiArray = [0,18.5,25,30,60];    /* BMI VALUES */
var weightDiv = false;
    
function calculateBMI()
{
    var height = document.bmi_calculator.bmi_height.value;    
    var weight = document.bmi_calculator.bmi_weight.value;    
    height = height.replace(',','.');
    weight = weight.replace(',','.');
    if(!useKg)weight = weight / 2.2;
    if(!useCm)height = height * 2.54;
    
    if(isNaN(height))return;
    if(isNaN(weight))return;
    
    height = height / 100;
    var bmi = weight / (height*height);
    createWeightBar(bmi);        
}

function createWeightBar(inputValue){
    
    if(!weightDiv){
        self.status = Math.random();
        weightDiv = document.createElement('DIV');
        weightDiv.style.width = barWidth + 'px';
        weightDiv.className='barContainer';
        weightDiv.style.left = Math.round((calculatorGraphObj.offsetWidth/2) + ((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px';
        calculatorGraphObj.appendChild(weightDiv);
        var span = document.createElement('SPAN');
        weightDiv.appendChild(span);
        
        var innerSpan = document.createElement('SPAN');
        innerSpan.className='labelSpan';
        span.appendChild(innerSpan);            
    }else{
        span = weightDiv.getElementsByTagName('SPAN')[0];
        innerSpan = weightDiv.getElementsByTagName('SPAN')[1];
    }
    var color = graphColors[graphColors.length-1];
    for(var no = bmiArray.length-1;no>0;no--){
        if(bmiArray[no]>inputValue)weightDiv.style.backgroundColor = graphColors[no-1];
    }
    if(inputValue/1>1){
        innerSpan.innerHTML = inputValue.toFixed(2); 
        span.style.display='inline';
    }else span.style.display='none';
    var height = Math.min(Math.round(barHeight * (inputValue / bmiArray[bmiArray.length-1])),barHeight-10);
    span.style.lineHeight = Math.round(height) + 'px';
    weightDiv.style.height = height + 'px';
    
}


function validateField()
{
    this.value = this.value.replace(/[^0-9,\.]/g,'');
    
}

function initBmiCalculator()
{
    calculatorObj = document.getElementById('dhtmlgoodies_bmi_calculator');    
    calculatorGraphObj = document.getElementById('bmi_calculator_graph');    
    if(!useCm)document.getElementById('bmi_label_height').innerHTML = 'inches';
    if(!useKg)document.getElementById('bmi_label_weight').innerHTML = 'pounds';
    
    var heightInput = document.getElementById('bmi_height');
    heightInput.onblur = validateField; 
    var widthInput = document.getElementById('bmi_height');
    widthInput.onblur = validateField; 
    
    var labelDiv = document.createElement('DIV');
    labelDiv.className = 'graphLabels';
    calculatorGraphObj.appendChild(labelDiv);
    for(var no=graphLabels.length-1;no>=0;no--){
        var colorDiv = document.createElement('DIV');
        colorDiv.className='square';
        colorDiv.style.backgroundColor = graphColors[no];
        colorDiv.innerHTML = '<span></span>';
        labelDiv.appendChild(colorDiv);
        
        var labelDivTxt = document.createElement('DIV');
        labelDivTxt.innerHTML = graphLabels[no];
        labelDiv.appendChild(labelDivTxt);
        labelDivTxt.className='label';
        
        if((no+1)%labelsPerRow==0){
            var clearDiv = document.createElement('DIV');
            clearDiv.className='clear';
            labelDiv.appendChild(clearDiv);                
        }        
    }
    var clearDiv = document.createElement('DIV');
    clearDiv.className='clear';
    labelDiv.appendChild(clearDiv);    
                    
    var graphDiv = document.createElement('DIV');
    graphDiv.className='barContainer';
    graphDiv.style.width = barWidth + 'px';
    graphDiv.style.left = Math.round(((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px';
    graphDiv.style.height = barHeight;
    calculatorGraphObj.appendChild(graphDiv);
    
    var totalHeight = 0;
    for(var no=bmiArray.length-1;no>0;no--){
        var aDiv = document.createElement('DIV');
        aDiv.style.backgroundColor = graphColors[no-1];
        aDiv.innerHTML = '<span></span>';
        var height = Math.round(barHeight * (bmiArray[no] - bmiArray[no-1]) / bmiArray[bmiArray.length-1]) - 1;
        aDiv.style.height = height + 'px';
        graphDiv.appendChild(aDiv);    
        
    }        
    
    createWeightBar(1);
}

</script>
</head>
<body>

<div id="dhtmlgoodies_bmi_calculator">
<div class="calculator_form">
    <form name="bmi_calculator">
        <table>
            <tr>
                <td><label for="bmi_height">키</label>:</td><td><input class="textInput" type="text" id="bmi_height" name="bmi_height"> <span id="bmi_label_height">cm</span></td>
            </tr>
            <tr>
                <td><label for="bmi_weight">몸무게</label>:</td><td><input class="textInput" type="text" id="bmi_weight" name="bmi_weight"> <span id="bmi_label_weight">kg</span></td>
            </tr>
            <tr>
                <td colspan="2"><input type="button" onclick="calculateBMI()" value="Find BMI"></td>
            </tr>
        </table>        
    </form>    
</div>
<div class="calculator_graph" id="bmi_calculator_graph">
</div>
</div>

<script type="text/javascript">
initBmiCalculator();
</script>

</body>
</html>

 

 

여기에서 키 몸무게 입력하고 Find BMI눌렀을시 

"당신이 3개월동안 감량 가능한 몸무게는 kg입니다" 이렇게 나오게 하고싶은데요 ㅠㅠ

고수님들 도움좀 주세요 ㅠㅠ 

 
0
    
 
0
        list
 
※ 짧은 댓글일수록 예의를 갖추어 작성해 주시기 바랍니다.
line
reply cancel
 
번호 제목 글쓴이 추천 조회 날짜
57  livesearch 선택시 input 입력  [1] member 홍총이 0 / 0 3821 2020-02-24
56  음료수 자판기 자바스크립트   member 초보자바 0 / 0 2228 2017-11-11
55  JSP 이용해 업로드 관련 질문입니다.   member SMWEI 0 / 0 1864 2017-08-16
54  비만도 계산 스크립트 질문드립니다 ㅠㅠ   member 샤샤 0 / 0 10598 2017-04-05
53  자동로그인   member 후루루하 0 / 0 1497 2017-03-10
52  자바 스크립트 관련 오류 질문....   member 프리웹마 0 / 0 1877 2016-12-17
51  value의 합에 따른 링크걸기   member Tigger 0 / 0 1440 2016-12-05
50  jsp 웹에서 날짜부분 문제가 있습니다.+전체코드  [1] member 마우스2개 0 / 0 3423 2016-11-01
49  안녕하세요. 정말 난감한 질문일지 모르겠지만....... 너무나 궁금하고 꼭해..   member obrago2 0 / 0 9136 2016-10-20
48  fsockopen 문의드립니다.  [1] member 꾸냥 0 / 0 1620 2016-08-28
47  마리아 DB 관련 질문 있습니다.   member 신의키스 0 / 0 1661 2016-04-07
46  select box 에 관해서  [1] member 지각생 개 0 / 0 1883 2014-10-01
45  영화관 홈페이지를 만드는데  [1] member 대학생 0 / 0 2864 2014-08-27
44  소스좀가르쳐주시면감사하겠습니다   member 초보초보 0 / 0 1942 2014-05-30
43  global.asa에 대한 질문입니다.   member 초보개발 0 / 0 2227 2014-01-24
42  간단하게 아이피 차단하는 소스좀 부탁드려요  [1] member 수그니 0 / 0 2437 2013-11-22
41  php 내의 동일한 페이지에서 서로 다른 데이터베이스에 접속하는 방법좀 알..   member 초급자 0 / 0 2598 2013-11-05
40  쿠키값을 이용해서 방문시마다 랜덤한 페이지를 보여주고 싶은데요   member 쿠쿠아라 0 / 0 2175 2013-10-23
39  asp 소스중에요 xss,sql injection,쿠키값인증로그인 보안 예제소스 주시면 감..   member 최용훈 0 / 0 3079 2013-08-26
38  PHP으로 제작된 프로그램을 JSP 변환 방법   member 권보월 0 / 0 10495 2013-07-01
37  컴퓨터 새내기로써 궁금한것 질문드립니다.   member 0 / 0 2667 2013-02-13
36  mySQL 질문입니다ㅠ   member 심연 0 / 0 2607 2013-01-23
35  주석좀 달아주세여~!   member 심지호 0 / 0 3049 2012-11-19
34  첨부파일 포함해서 메일 보내기  [1] member 0 / 0 3490 2012-01-02
33  오픈형 asp 게시판 인듯 한데요 어떤 보드인지 아시는 분 있으신가요?  [1] member JJ 0 / 0 6133 2011-11-11
write
[2] [3] button