0
        <tr> 
           <td>
               Delivery
           </td>
            <td>
               <div class="confdelivery">
                    <select id="NxtDay" name="NxtDay">
                         <option selected="selected" value="1">Normal Devliery + 10.00</option>
                            <option value="2">Next Day Delivery + 20.00</option>
                        </select>
                    </div>
                </td>
            </tr>
             <tr>
                <td>
                    Total
                </td>
                <td> 
                     @{
                var total = Model.CartTotal;
             }
            @total
                </td>
            </tr>

Basically if a user selects next day delivery. I want 20 to be added to @total?

1 Answer 1

3

I thing you are going about this the wrong way. You either update some input value with javascript, or use the NxtDay value in your controller action to assign the correct value, depending on the selection.

ADDED:

What you want to do is something like this: (I am assuming you are using jquery, since it come with MVC3).

HOWEVER: You should check out some tutorial if you are starting. This is pretty basic stuff and you won't go far without having to come back here unless to read up on this sutff.

<tr> 
   <td>
       Delivery
   </td>
    <td>
       <div class="confdelivery">
            <select id="NxtDay" name="NxtDay">
                <option selected="selected" value="10">Normal Devliery + 10.00</option>
                <option value="20">Next Day Delivery + 20.00</option>
            </select>
        </div>
    </td>
</tr>
 <tr>
    <td>
        Total
    </td>
    <td> 
        <span id="totalValue" style="display: none">@Model.CartTotal</span>
        <span id="totalWithShipping">0</span>
       <input id="hiddenTotal" type="hidden" value="0">
    </td>
</tr>

<script>
    $(document).ready(function () {
        $('#NxtDay').change(function() {
            addToTotal();
        });
    });
    function addToTotal(){
        $('#totalWithShipping').html($('#totalValue').html() + $("#NxtDay option:selected").val());
        $('#hiddenTotal').val($('#totalWithShipping').html());
    }
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

Is there a way if a user drops it down and selects an option it calls a function to go to the controller and then reload the page
@Beginner - Yeah, with ajax you can do this and update content without reloading the whole page. However, unless you are updating something from or to your underlying database, I recommend you use Javascript to update any values in your front end and save yourself the roundtrip.
@Beginner Updated it again... Added a hidden input so the value could travel back in your form post. And added Model.CartTotal to the totalValue prior to adding the shipping.
when added this adds 10 or 20 to the end of the total. Does not add them together. so £120.00 becomes £120.0020

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.