dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: 2 Drop down lists in table - not working!

  1. #1
    Join Date
    Jan 2011
    Posts
    2

    2 Drop down lists in table - not working!

    Hi,

    I've got some great code from here and it will be perfect for my site with some changes.

    The page is going to be a bike builder where people can choose multiple options and get a quote which updates itself. A second form will allow people to compare 2 bikes.

    They need to be in 2 seperate cells so that they can sit next to each other with tables describing what's in the dropdown.

    I can't get the 2nd form. I've added a second javascript and changed the var but I still can get it to work.

    If someone can spot my error or see a better way of doing it that I will be extremely grateful.

    Many, many thanks in advance.

    [HTML
    <html>
    <head>
    <title>Drop-down</title>
    <script language="JavaScript" type="text/javascript">

    function calc(){
    var totalStr = '|Frameset|Groupset|Wheels|Saddle|Handlebars|Tyres|Finishing Kit|Pedals|Powermeter\n'; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var i=1; i<=9; i++) {
    DDL = document.getElementById('dropDownList'+i);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[0].total.value=totalValue;
    if (cnt == 9) { alert(totalStr); } // for testing purposes
    }
    </script>
    <script language="JavaScript" type="text/javascript">
    function calc1(){
    var total1Str = '|Frameset|Groupset|Wheels|Saddle|Handlebars|Tyres|Finishing Kit|Pedals|Powermeter\n'; // for testing only
    var total1Value=0;
    var DDL1;
    var cnt1 = 0; // for testing only
    for (var j=10; j<=18; j++) {
    DDL1 = document.getElementById('dropDownList'+j);
    temp = DDL1.options[DDL1.selectedIndex].value;
    total1Value += Number(temp);
    if (DDL1.selectedIndex != 0) { total1Str += '|'+temp; cnt1++; } // cnt1++ is for testing only
    }
    document.forms[0].total.value=totallValue;
    if (cnt1 == 18) { alert(total1Str); } // for testing purposes
    }
    </script>
    <style type="text/css">
    .style1 {
    font-family: Tahoma;
    font-size: small;
    }
    .style2 {
    font-size: x-small;
    }
    .style3 {
    font-family: Tahoma;
    font-size: x-small;
    }
    </style>
    </head>
    <body>
    <table cellpadding="0" cellspacing="0" style="width: 100%">
    <tr>
    <td style="width: 90" valign="top">
    <table cellpadding="0" cellspacing="0" class="style1" style="width: 100%; height: 294px">
    <tr>
    <td>
    <table style="width: 100%">
    <tr>
    <td class="style2" style="height: 28" valign="top">Frame</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Groupset</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Wheels</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Saddle</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Handle Bars</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">Tyres</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Pedals</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Fininshing Kit</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Powermeter</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    <td>
    <table>
    <form id="dropDownForm" name="dropDownForm">
    <tr><td>
    &nbsp;<select id="dropDownList1" onChange="calc();" name="D1" style="width: 232px" >
    <option value="1000" selected="">TF100 Alloy</option>
    <option value="1200">TF300C Carbon</option>
    <option value="1300">TF400C Carbon</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList2" onChange="calc();" name="D2">
    <option value="1000" selected="">Miche</option>
    <option value="313.00">Miche 10sp +100</option>


    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList3" onChange="calc();" name="D3">
    <option value="200" selected="">Miche</option>
    <option value="100">Standard </option>

    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList4" onChange="calc();" name="D4">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">Standard RED LED</option>

    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList5" onChange="calc();" name="D5">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">Standard </option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList6" onChange="calc();" name="D6">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">ABC</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList7" onChange="calc();" name="D7">
    <option value="200" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Stand</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList8" onChange="calc();" name="D8">
    <option value="200" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList9" onChange="calc();" name="D9">
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td valign="top">
    <span class="style3">Total Value&nbsp; </span>&nbsp;<input readonly onFocus="blur()" type="text" size="4" name="total" value="1000" style="width: 46px">
    </td></tr>
    </form>
    </table>
    </td>
    <td>
    <table cellpadding="0" cellspacing="0" class="style1" style="width: 100%; height: 294px">
    <tr>
    <td>
    <table style="width: 100%">
    <tr>
    <td class="style2" style="height: 28" valign="top">Frame</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Groupset</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Wheels</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Saddle</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Handle Bars</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">Tyres</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Pedals</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Fininshing Kit</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Powermeter</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    <td>
    <table>
    <form id="dropDownForm1" name="dropDownForm1">
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList10" onChange="calc1();" style="width: 231px" >
    <option value="100" selected="">TF100</option>
    <option value="120">TF300C</option>

    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList11" onChange="calc1();" >
    <option value="100" selected="">Miche9sp</option>
    <option value="313.00">Miche10sp +100</option>

    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList12" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList13" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList14" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList15" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList16" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList17" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList18" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td valign="top" style="width: 236px">
    <span class="style3">Total Value&nbsp; </span>&nbsp;<input readonly onFocus="blur()" type="text" size="4" name="total" value="1000" style="width: 46px">
    </td></tr>
    </form>
    </table>

    </td>
    </tr>

    </html>
    [/HTML]

  2. #2
    Join Date
    Jan 2011
    Posts
    2
    Problem found in red below:

    <script language="JavaScript" type="text/javascript">

    function calc2(){
    var totalStr = ''; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var j=1; j<=9; j++) {
    DDL = document.getElementById('dropDownList'+j);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[0].total.value=totalValue;
    }
    </script>
    <script language="JavaScript" type="text/javascript">

    function calc3(){
    var totalStr = ''; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var j=10; j<=18; j++) {
    DDL = document.getElementById('dropDownList'+j);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[1].total.value=totalValue;
    }
    </script>


    It had nothing to do with naming variables differently!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles