开发者

how can we change the value by using radio buttons

I am making a website in Adobe Dreamweaver with php. In the site there’s a 3 buttons for selecting payment method that will act as the continue button. What I want is when the user checks a radio but开发者_开发知识库tons (I agree button), it will be add with that amount and display with previous amount.. there is three buttons which has the corresponding values(amount in pounds)..

plz check my website http://www.spsmobile.co.uk in this linkgo to mobile phone unlocking and after add the cart click make payment it will go to next page there is a delivery mail details.. for that delivery mail details only am asking.. here i mentioned code:

<input id="radio-1" type="radio" name="rmr" value="1"> 
<label for="radio-1">£3</label> <input id="radio-2" type="radio" name="rmr" value="2">     
<label for="radio-2">£5.5</label> 
<input id="radio-3" type="radio" name="rmr" value="4"> 
<label for="radio-3">£10</label>  


<div class="total-text" style="font-size:36px">£10</div> 



  var total = parseInt($("div.total-text").text().substring(1), 10);  
    $("input[name='rmr']").bind('change', function() {     
      var amount = 0;     
      switch (this.value) {     
              case "1":         
                          amount = 3;         
                          break;     
              case "2":         
                          amount = 5.5;                          
                          break;     
              case "4":         
                          amount = 10;         
                          break;     
      }      
      $("div.total-text").text("£" + (total + amount)); 
   }); 

but there is no change , my previous amount did not add with that. while am clicking previous amount only displayed on browser.. i need when i cliks radio button the value should change correspondingly.. where i did that mistake...plz give me some idea and what should i do..is there any need for storing db..

thanks in adv


is this [demo ] is not functionality you're looking for?


use "click" event instead of "change" event. Modify below line as:

$("input[name='rmr']").bind('click', function() { .... }


You wanna count every time u clicked on a radtio button it counts the value on the previous click(when first time clicked the value is zero). I would create an hidden field to put the totale amount in.

In your example u used 'this' if ur writing in jQuery you cant use it that way(in my opinion). If your writing a function like:

function foo(value)
{
   this.value = value;
};

var foobar = new foo('test');
alert(foobar.value);

Then u should use the way u did.

<script type="text/javascript">
$(document).ready(function() {
    $("input[name=rmr]").click(function() {

            //Get totale amount
        var total  = parseInt($("input[name=mem-totale]").val());
            //Get checked value
        var amount = parseInt($(this).val());       

            //Change it in your way
        switch (amount) {     
              case "1":         
                  amount = 3;         
                  break;     
              case "2":         
                  amount = 5.5;                          
                  break;     
              case "4":         
                  amount = 10;         
                  break;     
        };

            var totale_amount = total + amount;

            //Put totale in the mem-totale
        $("input[name=mem-totale]").val(totale_amount);
            //Put tottale in your label
        $("div.total-text").text("£" + (totale_amount)); 
    });
});
</script> 

<input id="radio-1" type="radio" name="rmr" value="1"> 
<label for="radio-1">£3</label>
<input id="radio-2" type="radio" name="rmr" value="2">     
<label for="radio-2">£5.5</label> 
<input id="radio-3" type="radio" name="rmr" value="4"> 
<label for="radio-3">£10</label>  

<div class="total-text" style="font-size:36px">£10</div>
<input type="hidden" name="mem-totale" value="0" />

Goodluck with it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜