need select menu to change var code in <head>

Discussion in 'JavaScript' started by jumpajoe, Aug 20, 2007.

  1. #1
    Hello...
    I have been trying to figure this out on my own but no can do....

    I have a script in the <head> such as
    _______________________________
    function total(what,number) {
    var grandTotal = 599;
    for (var i=0;i<number;i++) {
    if (what.elements['price' + i].value == '')
    what.elements['price' + i].value = '0.00';
    blahblahblah
    _____________________________

    I need to figure out how i can have a select drop down menu where the user can select an option which will change the grandTotal number in that code....

    any ideas?
    thank you.
     
    jumpajoe, Aug 20, 2007 IP
  2. mjamesb

    mjamesb Member

    Messages:
    88
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #2
    You have the variable grandtotal scoped locally inside the function. You need to make it a global variable so it can be accessed both outside and inside the function.

    <script>
    var grandTotal = 0;

    function total(what,number) {

    for (var i=0;i<number;i++) {
    if (what.elements['price' + i].value == '')
    what.elements['price' + i].value = '0.00';
    }
    function SetGrandTotal(value)
    {
    grandTotal = value;
    }
    </script>

    <body>
    <select onchange="SetGrandTotal(this.value);"><option value="100">100<option value="200">200</select>
    </body>
     
    mjamesb, Aug 20, 2007 IP