안녕하세요 .ㅠㅠ 요금계산 jqery 코드를 넣었는데 게시판에 나오지 않습니다

function kboard_set_date(){
	var start_date = new Date(jQuery('#kboard_option_start_date').val());
	var end_date = new Date(jQuery('#kboard_option_end_date').val());
	var diff_date = (end_date.getTime() - start_date.getTime()) / (1000*60*60*24);
	var price = 0;
	
	var indoor_outdoor = jQuery('input[name="kboard_option_indoor_outdoor"]:checked').val();
	if(typeof indoor_outdoor === 'undefined'){
		alert('실외/실내를 선택해주세요.');
	}
	else{
		if(indoor_outdoor == '제1여객터미널실내'){
			// 제1여객터미널실내 기준 가격
			switch(diff_date){
				case 1: price = 45000; break;
				case 2: price = 45000; break;
				case 3: price = 45000; break;
				case 4: price = 60000; break;
				case 5: price = 75000; break;
				case 6: price = 85000; break;
				case 7: price = 95000; break;
				case 8: price = 105000; break;
				case 9: price = 115000; break;
				case 10: price = 125000; break;
				case 11: price = 135000; break;
				case 12: price = 145000; break;
				case 13: price = 155000; break;
				case 14: price = 165000; break;
				case 15: price = 175000; break;
				case 16: price = 185000; break;
				case 17: price = 195000; break;
				case 18: price = 205000; break;
				case 19: price = 215000; break;
				case 20: price = 225000; break;
				default: price = 0; break;
			}
		}
		else{
			// 제1여객터미널실외 기준 가격
			switch(diff_date){
				case 1: price = 30000; break;
				case 2: price = 30000; break;
				case 3: price = 30000; break;
				case 4: price = 36000; break;
				case 5: price = 45000; break;
				case 6: price = 50000; break;
				case 7: price = 55000; break;
				case 8: price = 60000; break;
				case 9: price = 65000; break;
				case 10: price = 70000; break;
				case 11: price = 75000; break;
				case 12: price = 80000; break;
				case 13: price = 85000; break;
				case 14: price = 90000; break;
				case 15: price = 95000; break;
				case 16: price = 100000; break;
				case 17: price = 105000; break;
				case 18: price = 110000; break;
				case 19: price = 115000; break;
				case 20: price = 120000; break;
				default: price = 0; break;
			}
		}
		else{
			// 제2여객터미널실외 기준 가격
			switch(diff_date){
				case 1: price = 40000; break;
				case 2: price = 40000; break;
				case 3: price = 40000; break;
				case 4: price = 46000; break;
				case 5: price = 55000; break;
				case 6: price = 60000; break;
				case 7: price = 65000; break;
				case 8: price = 70000; break;
				case 9: price = 75000; break;
				case 10: price = 80000; break;
				case 11: price = 85000; break;
				case 12: price = 90000; break;
				case 13: price = 95000; break;
				case 14: price = 100000; break;
				case 15: price = 105000; break;
				case 16: price = 110000; break;
				case 17: price = 115000; break;
				case 18: price = 120000; break;
				case 19: price = 125000; break;
				case 20: price = 130000; break;
				default: price = 0; break;
			}
		}
		else{
			// 제2여객터미널실내 기준 가격
			switch(diff_date){
				case 1: price = 55000; break;
				case 2: price = 55000; break;
				case 3: price = 55000; break;
				case 4: price = 75000; break;
				case 5: price = 85000; break;
				case 6: price = 95000; break;
				case 7: price = 105000; break;
				case 8: price = 115000; break;
				case 9: price = 125000; break;
				case 10: price = 135000; break;
				case 11: price = 145000; break;
				case 12: price = 155000; break;
				case 13: price = 165000; break;
				case 14: price = 175000; break;
				case 15: price = 185000; break;
				case 16: price = 195000; break;
				case 17: price = 205000; break;
				case 18: price = 215000; break;
				case 19: price = 225000; break;
				case 20: price = 235000; break;
				default: price = 0; break;
			}
		}
		jQuery('input[name="kboard_option_price"]').val(price);
	}
}

현재 코드를 script.js 이렇게 넣었는데요 .. 하지만 선택시 ㅠㅠ요금계산이 나오지 않습니다 

코드를 잘못한게 있는걸까요 ?  언제나 좋은 게시판 만들어주셔서 감사합니다 ㅠㅠ 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 안녕하세요~^^

    올려주신 코드를 확인해보니 if문을 잘못 사용하신 듯합니다.

    아래의 코드를 활용해보시겠어요?

    if(indoor_outdoor == '제1여객터미널실내'){
    ...
    }
    else if(indoor_outdoor == '제1여객터미널실외'){
    ...
    }
    else if(indoor_outdoor == '제2여객터미널실외'){
    ...
    }
    else{
    ...
    }

     

    자바스크립트 if문에 대한 자세한 내용은

    아래의 링크도 참고해보시겠어요?

    https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/if...else

    고맙습니다.

  • function kboard_set_date(){
    	var start_date = new Date(jQuery('#kboard_option_start_date').val());
    	var end_date = new Date(jQuery('#kboard_option_end_date').val());
    	var diff_date = (end_date.getTime() - start_date.getTime()) / (1000*60*60*24);
    	var price = 0;
    	
    	var indoor_outdoor = jQuery('input[name="kboard_option_indoor_outdoor"]:checked').val();
    	if(typeof indoor_outdoor === 'undefined'){
    		alert('실외/실내를 선택해주세요.');
    	}
    	else{
    		if(indoor_outdoor == '제1여객터미널실내'){
    ...
    }
    else if(indoor_outdoor == '제1여객터미널실외'){
    ...
    }
    else if(indoor_outdoor == '제2여객터미널실외'){
    ...
    }
    else if(indoor_outdoor == '제2여객터미널실내'){
    ...
    }
    else{
    ...
    }
    			// 제1여객터미널실내 기준 가격
    			switch(diff_date){
    				case 1: price = 45000; break;
    				case 2: price = 45000; break;
    				case 3: price = 45000; break;
    				case 4: price = 60000; break;
    				case 5: price = 75000; break;
    				case 6: price = 85000; break;
    				case 7: price = 95000; break;
    				case 8: price = 105000; break;
    				case 9: price = 115000; break;
    				case 10: price = 125000; break;
    				case 11: price = 135000; break;
    				case 12: price = 145000; break;
    				case 13: price = 155000; break;
    				case 14: price = 165000; break;
    				case 15: price = 175000; break;
    				case 16: price = 185000; break;
    				case 17: price = 195000; break;
    				case 18: price = 205000; break;
    				case 19: price = 215000; break;
    				case 20: price = 225000; break;
    				default: price = 0; break;
    			}
    		}
    		else{
    			// 제1여객터미널실외 기준 가격
    			switch(diff_date){
    				case 1: price = 30000; break;
    				case 2: price = 30000; break;
    				case 3: price = 30000; break;
    				case 4: price = 36000; break;
    				case 5: price = 45000; break;
    				case 6: price = 50000; break;
    				case 7: price = 55000; break;
    				case 8: price = 60000; break;
    				case 9: price = 65000; break;
    				case 10: price = 70000; break;
    				case 11: price = 75000; break;
    				case 12: price = 80000; break;
    				case 13: price = 85000; break;
    				case 14: price = 90000; break;
    				case 15: price = 95000; break;
    				case 16: price = 100000; break;
    				case 17: price = 105000; break;
    				case 18: price = 110000; break;
    				case 19: price = 115000; break;
    				case 20: price = 120000; break;
    				default: price = 0; break;
    			}
    		}
    		else{
    			// 제2여객터미널실외 기준 가격
    			switch(diff_date){
    				case 1: price = 40000; break;
    				case 2: price = 40000; break;
    				case 3: price = 40000; break;
    				case 4: price = 46000; break;
    				case 5: price = 55000; break;
    				case 6: price = 60000; break;
    				case 7: price = 65000; break;
    				case 8: price = 70000; break;
    				case 9: price = 75000; break;
    				case 10: price = 80000; break;
    				case 11: price = 85000; break;
    				case 12: price = 90000; break;
    				case 13: price = 95000; break;
    				case 14: price = 100000; break;
    				case 15: price = 105000; break;
    				case 16: price = 110000; break;
    				case 17: price = 115000; break;
    				case 18: price = 120000; break;
    				case 19: price = 125000; break;
    				case 20: price = 130000; break;
    				default: price = 0; break;
    			}
    		}
    		else{
    			// 제2여객터미널실내 기준 가격
    			switch(diff_date){
    				case 1: price = 55000; break;
    				case 2: price = 55000; break;
    				case 3: price = 55000; break;
    				case 4: price = 75000; break;
    				case 5: price = 85000; break;
    				case 6: price = 95000; break;
    				case 7: price = 105000; break;
    				case 8: price = 115000; break;
    				case 9: price = 125000; break;
    				case 10: price = 135000; break;
    				case 11: price = 145000; break;
    				case 12: price = 155000; break;
    				case 13: price = 165000; break;
    				case 14: price = 175000; break;
    				case 15: price = 185000; break;
    				case 16: price = 195000; break;
    				case 17: price = 205000; break;
    				case 18: price = 215000; break;
    				case 19: price = 225000; break;
    				case 20: price = 235000; break;
    				default: price = 0; break;
    			}
    		}
    		jQuery('input[name="kboard_option_price"]').val(price);
    	}
    }

    안녕하세요 말씀해주신 코드와 참고자료보고 이렇게 코드를 변경해봤는데요 ㅠㅜ 그래도 금액이 나오지 않는데 혹시이것은 

    <?php
    if(isset($_GET['ymd'])){
    	$ymd = date('Y-m-d', strtotime($_GET['ymd']));
    }
    $today = date('Y-m-d', current_time('timestamp'));
    ?>
    <div class="kboard-attr-row">
    	<label class="attr-name" for="kboard_option_start_date"><?php echo __('인도일시', 'kboard-cross-calendar')?></label>
    	<div class="attr-value">
    		<div class="calendar-event-start-date-set">
    			<input type="text" class="datepicker" id="kboard_option_start_date" name="kboard_option_start_date" value="<?php echo $content->option->start_date ? $content->option->start_date : (isset($ymd) ? $ymd : $today)?>" title="<?php echo __('Start Date Setting', 'kboard-cross-calendar')?>" readonly>
    			<input type="text" class="timepicker" name="kboard_option_start_time" maxlength="5" value="<?php echo $content->option->start_time ? $content->option->start_time : date('H:i', strtotime('9:00'))?>" title="<?php echo __('Start Time Setting', 'kboard-cross-calendar')?>">
    		</div>
    	</div>
    </div>
    
    <div class="kboard-attr-row">
    	<label class="attr-name" for="kboard_option_end_date"><?php echo __('인수일시', 'kboard-cross-calendar')?></label>
    	<div class="attr-value">
    		<div class="calendar-event-end-date-set">
    			<input type="text" class="datepicker" id="kboard_option_end_date" name="kboard_option_end_date" value="<?php echo $content->option->end_date ? $content->option->end_date : (isset($ymd) ? $ymd : $today)?>" title="<?php echo __('End Date Setting', 'kboard-cross-calendar')?>" readonly>
    			<input type="text" class="timepicker" name="kboard_option_end_time" maxlength="5" value="<?php echo $content->option->end_time ? $content->option->end_time : date('H:i', strtotime('18:00'))?>" title="<?php echo __('End Time Setting', 'kboard-cross-calendar')?>">
    			<label><br>이용요금<input type="text" name="kboard_option_price" value="<?php echo $content->option->content?>" readonly>
    		</div>
    	</div>

    이 코드가 잘못된것일까요 .. ㅠㅠ 언제나  감사합니다 

  • 저희가 안내해드린 코드를 그대로 적용하시면 정상적으로 동작하지 않습니다.

    안내해드린 코드 중 ... 부분은 생략을 나타내며

    실제로는 코드를 입력해주셔야 합니다.

    스크립트 쪽 코드는 아래의 코드로 교체해서 테스트해보시겠어요?

    function kboard_set_date(){
    	var start_date = new Date(jQuery('#kboard_option_start_date').val());
    	var end_date = new Date(jQuery('#kboard_option_end_date').val());
    	var diff_date = (end_date.getTime() - start_date.getTime()) / (1000*60*60*24);
    	var price = 0;
    	
    	var indoor_outdoor = jQuery('input[name="kboard_option_indoor_outdoor"]:checked').val();
    	if(typeof indoor_outdoor === 'undefined'){
    		alert('실외/실내를 선택해주세요.');
    	}
    	else{
    		if(indoor_outdoor == '제1여객터미널실내'){
    			// 제1여객터미널실내 기준 가격
    			switch(diff_date){
    				case 1: price = 45000; break;
    				case 2: price = 45000; break;
    				case 3: price = 45000; break;
    				case 4: price = 60000; break;
    				case 5: price = 75000; break;
    				case 6: price = 85000; break;
    				case 7: price = 95000; break;
    				case 8: price = 105000; break;
    				case 9: price = 115000; break;
    				case 10: price = 125000; break;
    				case 11: price = 135000; break;
    				case 12: price = 145000; break;
    				case 13: price = 155000; break;
    				case 14: price = 165000; break;
    				case 15: price = 175000; break;
    				case 16: price = 185000; break;
    				case 17: price = 195000; break;
    				case 18: price = 205000; break;
    				case 19: price = 215000; break;
    				case 20: price = 225000; break;
    				default: price = 0; break;
    			}
    		}
    		else if(indoor_outdoor == '제1여객터미널실외'){
    			// 제1여객터미널실외 기준 가격
    			switch(diff_date){
    				case 1: price = 30000; break;
    				case 2: price = 30000; break;
    				case 3: price = 30000; break;
    				case 4: price = 36000; break;
    				case 5: price = 45000; break;
    				case 6: price = 50000; break;
    				case 7: price = 55000; break;
    				case 8: price = 60000; break;
    				case 9: price = 65000; break;
    				case 10: price = 70000; break;
    				case 11: price = 75000; break;
    				case 12: price = 80000; break;
    				case 13: price = 85000; break;
    				case 14: price = 90000; break;
    				case 15: price = 95000; break;
    				case 16: price = 100000; break;
    				case 17: price = 105000; break;
    				case 18: price = 110000; break;
    				case 19: price = 115000; break;
    				case 20: price = 120000; break;
    				default: price = 0; break;
    			}
    		}
    		else if(indoor_outdoor == '제2여객터미널실외'){
    			// 제2여객터미널실외 기준 가격
    			switch(diff_date){
    				case 1: price = 40000; break;
    				case 2: price = 40000; break;
    				case 3: price = 40000; break;
    				case 4: price = 46000; break;
    				case 5: price = 55000; break;
    				case 6: price = 60000; break;
    				case 7: price = 65000; break;
    				case 8: price = 70000; break;
    				case 9: price = 75000; break;
    				case 10: price = 80000; break;
    				case 11: price = 85000; break;
    				case 12: price = 90000; break;
    				case 13: price = 95000; break;
    				case 14: price = 100000; break;
    				case 15: price = 105000; break;
    				case 16: price = 110000; break;
    				case 17: price = 115000; break;
    				case 18: price = 120000; break;
    				case 19: price = 125000; break;
    				case 20: price = 130000; break;
    				default: price = 0; break;
    			}
    		}
    		else{
    			// 제2여객터미널실내 기준 가격
    			switch(diff_date){
    				case 1: price = 55000; break;
    				case 2: price = 55000; break;
    				case 3: price = 55000; break;
    				case 4: price = 75000; break;
    				case 5: price = 85000; break;
    				case 6: price = 95000; break;
    				case 7: price = 105000; break;
    				case 8: price = 115000; break;
    				case 9: price = 125000; break;
    				case 10: price = 135000; break;
    				case 11: price = 145000; break;
    				case 12: price = 155000; break;
    				case 13: price = 165000; break;
    				case 14: price = 175000; break;
    				case 15: price = 185000; break;
    				case 16: price = 195000; break;
    				case 17: price = 205000; break;
    				case 18: price = 215000; break;
    				case 19: price = 225000; break;
    				case 20: price = 235000; break;
    				default: price = 0; break;
    			}
    		}
    		jQuery('input[name="kboard_option_price"]').val(price);
    	}
    }

     

    구현하시려는 요금 계산 기능은 jQuery에 대해 어느 정도 지식이 있어야 수월할 듯합니다.

    고맙습니다.

  • 정말로 감사합니다 ㅠㅠㅠ 말씀하신 코드대로 넣기는 했으나 아직까지 요금이 안나옵니다 .. 아무래도 script.js 코드는 틀리지는 않은 것 같은데 
     editor-fields.php 파일에 넣은 

    <?php
    if(isset($_GET['ymd'])){
    	$ymd = date('Y-m-d', strtotime($_GET['ymd']));
    }
    $today = date('Y-m-d', current_time('timestamp'));
    ?>
    <div class="kboard-attr-row">
    	<label class="attr-name" for="kboard_option_start_date"><?php echo __('인도일시', 'kboard-cross-calendar')?></label>
    	<div class="attr-value">
    		<div class="calendar-event-start-date-set">
    			<input type="text" class="datepicker" id="kboard_option_start_date" name="kboard_option_start_date" value="<?php echo $content->option->start_date ? $content->option->start_date : (isset($ymd) ? $ymd : $today)?>" title="<?php echo __('Start Date Setting', 'kboard-cross-calendar')?>" readonly>
    			<input type="text" class="timepicker" name="kboard_option_start_time" maxlength="5" value="<?php echo $content->option->start_time ? $content->option->start_time : date('H:i', strtotime('9:00'))?>" title="<?php echo __('Start Time Setting', 'kboard-cross-calendar')?>">
    		</div>
    	</div>
    </div>
    
    <div class="kboard-attr-row">
    	<label class="attr-name" for="kboard_option_end_date"><?php echo __('인수일시', 'kboard-cross-calendar')?></label>
    	<div class="attr-value">
    		<div class="calendar-event-end-date-set">
    			<input type="text" class="datepicker" id="kboard_option_end_date" name="kboard_option_end_date" value="<?php echo $content->option->end_date ? $content->option->end_date : (isset($ymd) ? $ymd : $today)?>" title="<?php echo __('End Date Setting', 'kboard-cross-calendar')?>" readonly>
    			<input type="text" class="timepicker" name="kboard_option_end_time" maxlength="5" value="<?php echo $content->option->end_time ? $content->option->end_time : date('H:i', strtotime('18:00'))?>" title="<?php echo __('End Time Setting', 'kboard-cross-calendar')?>">
    			<label><br>이용요금<input type="text" name="kboard_option_price" value="<?php echo $content->option->content?>" readonly>
    		</div>
    	</div>

    이 코드가 문제인걸까요 .. ㅠㅠㅠ 원래 이용요금의 경우 값이 없을때 0 이라는 값이라도 나오는데 0값도 안나오고 아예 공백이어서 추측해봅니ㅏㄷ다 ..감사합니다 

  • 이전에 올려주신 페이지 주소로 확인해보니

    실외/실내 쪽 라디오 버튼에 kboard_set_date 함수를 실행하는

    onclick 이벤트가 추가되어 있지 않은 듯합니다.

    아래 링크에 남겨드린 댓글을 참고하셔서 onclick 이벤트를 추가해보시겠어요?

    https://www.cosmosfarm.com/threads/document/30503

    고맙습니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기