2016-08-09 3 views
-1

좋아, 내 변수 값이 자바 스크립트를 통해 변경되는 라디오 버튼이 있습니다. 변경된 값을 <h> 태그에 표시하고 있습니다. 이제이 <h> 태그 값을 데이터베이스에 게시하려고합니다. 나도 알아 <h> 태그는 양식 요소가 아니며 다른 솔루션은 숨겨진 입력 태그를 사용하고 있습니다. 라디오 버튼에서 값을 표시라벨 값을 게시하는 방법은 무엇입니까?

<script type="text/javascript"> 
    $(document).ready(function(){ 
    $('#delivery1,#delivery2').change(function(){ 
    price = $('#price').text(); 
    finals = $('#finals').text(); 
    finals1 = $('#HIDDENPRICE').text(); 

    if($('#delivery2').is(':checked')) { 
     price = (price)*1 + 40; 
     finals=price; 
     finals1=price;  
    } else { 
     price = (price)*1 - 40; 
     finals=price; 
     finals1=price; 
    } 
    $('#price').text(price); 
    $('#finals').text(price); 
    $('#HIDDENPRICE').text(price); 
    }); 
}); 
    </script> 

:

<label><input type="radio" name="optradio" id="delivery1" value="normal" checked><span class="label label-success">Regular Delivery</span></label><label>If you choose regular Delivery, it will take atleast 4 days time to deliver your product.(There will be no extra charges applied)</label> 
<label><input type="radio" name="optradio" id="delivery2" value="fast"><span class="label label-danger">One Day Delivery</span></label> 
       <label>If you choose One Day Delivery, product(s) will be delivered to you in 24 hours. (40 Rs Will be charged extra.) </label> 

그것에 대해 JS :

<h5><strong>Total</strong> 
<h5 id="price" name="finalprice"> 


<?php 
$finalprice=$item_total; 
echo $finalprice; 
?> 
</h5> 
</h5> 

이 지금은이 태그 값이 데이터베이스에 게시 할 여기 내 HTML 코드입니다. 어떤 해결책?

+0

' ' ". 나는 태그가 없습니다 숨겨진 입력 태그를 사용하는 양식 요소 및 기타 솔루션 알고"- 그 자신의 질문에 대답하지 않습니다? 네가 지금 어디서 붙어 있는지 분명하지 않다. – David

+0

Idk하지만 지난 10 시간 동안 끊임없이 코드를 작성하고 있습니다. 어쩌면 내 마음이 뚝뚝 거릴 것입니다. 그러기 위해서는 빠른 구문이 필요합니다. –

+0

* * * 일을하기 위해서? 어디서 붙어 있는지 모를 경우 어떻게 문제가 있는지 어떻게 알 수 있습니까? – David

답변

0

숨겨진 입력 필드로 시도하십시오. 이것을보십시오.

$(document).ready(function(){ 
    $('#delivery1,#delivery2').change(function(){ 
    price = $('#price').text(); 
    if($('#delivery2').is(':checked')) { 
     price = parseInt(price) + 40; 

    } else { 
     price = parseInt(price) - 40; 
    } 
    $('#price').text(price); 
    $('#final_price').val(price); 
    }); 
}); 

https://jsfiddle.net/rijink121/5vcvt527/4/

+0

항상 그렇듯이 @ Rijin 코드 만 도움 : P Thanks Mate! –

-1
You can use the ajax call for this. 
$("button").click(function(){ 
    $.post("test_post.php",{ finalprice: 'your final price',}, 
    function(data){ 
     alert(data); // the return data on success 
    }); 
}); 


In the test_post.php you can write the database operation and also you can get the value in the post variable like 
$_POST['finalprice'] 
관련 문제